摸爬滚打DirectX11_day02——VS2010+DirectX11的环境配置

由于本人希望从DirectX11的基础sample开始学习,所以选择了

VS2010+Microsoft DirectX SDK(June 2010)的开发环境

学习龙书DirectX11版本,运行课本的Sample必须要在VS2010的环境下,不然会报错,想要完全专注于DX11的学习,那么请选择VS2010。


安装Microsoft DirectX SDK(June 2010)

安装失败 S1023的解决方案
卸载

Microsoft Visual C++ 2010 x86 Redistributable

Microsoft Visual C++ 2010 x64 Redistributable
以及所有Runtime文件。

如果还是报错,查看C:\Windows\Logs的日志DXError
[12/10/16 15:44:31] module: dxupdate(Jun 2 2010), file: dxupdate.cpp, line: 2223, function: RegisterDLL

Failed API:     LoadLibraryEx()
Error:      (193) - %1 不是有效的 Win32 应用程序。



Unable to load C:\Windows\system32\xactengine2_0.dll.

[12/10/16 15:44:31] module: dxupdate(Jun 2 2010), file: dxupdate.cpp, line: 5848, function: DirectXUpdateInstallPlugIn

RegisterDllFromSection() failed.

[12/10/16 15:44:31] module: dsetup32(Jun 2 2010), file: dxupdate.cpp, line: 280, function: CSetup::InstallPlugIn

DirectXUpdateInstallPlugIn() failed.

[12/10/16 15:44:31] module: dsetup32(Jun 2 2010), file: setup.cpp, line: 1723, function: CSetup::SetupForDirectX

InstallPlugIn() failed.

此时参照此博客的解决方案

解决Unable to load C:\Windows\system32\xactengine2_0.dll.


DirectX11在VS2010的配置

基本配置可以参考
浅墨逐梦旅程

博主可能点背,遇到了各种各样的问题

#include <Windows.h>
#include <d3dx9.h>
#include <MMSystem.h>
LPDIRECT3D9 g_pD3D;
LPDIRECT3DDEVICE9 g_pd3dDevice;
LPDIRECT3DVERTEXBUFFER9 g_pVB;
struct CUSTOMVERTEX{    
    FLOAT x, y, z;    
    DWORD color;
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
HRESULT InitObject()
{    
    CUSTOMVERTEX triangle[] =     
    {        
        { -1.0f,-1.0f, 0.0f, 0xffff0000, },        
        {  1.0f,-1.0f, 0.0f, 0xff0000ff, },        
        {  0.0f, 1.0f, 0.0f, 0xffffffff, }  
    };    
    if (FAILED(g_pd3dDevice->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL)))        
        return E_FAIL;    
    VOID* pVertices;    
    if (FAILED(g_pVB->Lock(0,sizeof(triangle), &pVertices, 0)))        
        return E_FAIL;    
    memcpy(pVertices, triangle, sizeof(triangle));    
    g_pVB->Unlock();    
    return S_OK;
}
HRESULT InitD3D(HWND hWnd)
{    
    g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);    
    if (NULL == g_pD3D)        
        return E_FAIL;    
    D3DPRESENT_PARAMETERS d3dpp;    
    ZeroMemory(&d3dpp, sizeof(d3dpp));    
    d3dpp.Windowed = TRUE;    
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;    
    if(FAILED( g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,                                         
        hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,                                        
        &d3dpp, &g_pd3dDevice)))    
    {        
        return E_FAIL;    
    }    
    g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);    
    // Turn off D3D lighting, since we are providing our own vertex colors    
    g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );    
    if (FAILED(InitObject()))        
        return E_FAIL;    
    return S_OK;
}
void SetupMatrices()
{    
    D3DXMATRIX matWorld;    
    UINT iTime = timeGetTime() % 1000;    
    FLOAT fAngle = iTime * ( 2.0f * D3DX_PI ) / 1000.0f;    
    D3DXMatrixRotationY(&matWorld, fAngle);    
    g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);    
    D3DXVECTOR3 vEyePt(0.0f, 3.0f, -5.0f);    
    D3DXVECTOR3 vLookAtPt(0.0f, 0.0f, 0.0f);    
    D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f);    
    D3DXMATRIXA16 matView;    
    D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookAtPt, &vUp);    
    g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView);    
    D3DXMATRIX matPoj;    
    D3DXMatrixPerspectiveFovLH(&matPoj, D3DX_PI/4, 1.0f, 1.0f, 100.0f);    
    g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matPoj);
}
void Render()
{    
    g_pd3dDevice->Clear(0,NULL,  D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);    
    g_pd3dDevice->BeginScene();    
    SetupMatrices();    
    g_pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX));    
    g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);    
    g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);    
    g_pd3dDevice->EndScene();    
    g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
}
void Cleanup()
{    
    if (g_pd3dDevice)        
        g_pd3dDevice->Release();    
    if (g_pD3D)        
        g_pD3D->Release();    
    if (g_pVB)        
        g_pVB->Release();
}
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{    
    switch (msg)    
    {    
    case WM_DESTROY:       
        PostQuitMessage(0);        
        return 0;    
    case WM_PAINT:        
        ValidateRect(hWnd, NULL);        
        return 0;   
    }    
    return DefWindowProc(hWnd, msg, wParam, lParam);
}
INT WINAPI WinMain(__in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
{    
    WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0, 0,    GetModuleHandle(NULL), NULL, NULL, NULL, NULL,     L"Direct3D", NULL};    
    RegisterClassEx(&wc);    
    // Create the application window    
    HWND hWnd = CreateWindow(L"Direct3D", 
        L"Learn", WS_OVERLAPPEDWINDOW,        
        100, 100, 300, 300,         
        GetDesktopWindow(), 
        NULL, wc.hInstance, NULL);    
    //
    ShowWindow(hWnd, SW_SHOW);    
    if (SUCCEEDED(InitD3D(hWnd)))    
    {
        ShowWindow(hWnd, SW_SHOWDEFAULT);        
        UpdateWindow(hWnd);       
        MSG msg;        
        ZeroMemory(&msg, sizeof(msg));    
        while (msg.message != WM_QUIT)   
        {         
            if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))     
            {           
                TranslateMessage(&msg);     
                DispatchMessage(&msg);      
            }          
            else           
                Render();       
        }           
    }       
    UnregisterClass( L"Direct3D", wc.hInstance );    
    Cleanup();
    return nShowCmd;
}

这是一个Sample,运行时编译器报错。

错误描述:

1>正在编译资源…
1>正在编译资源清单…
1>正在链接…
1>LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
1>生成日志保存在“file://E:\HelloC\ShapeFill V11\ShapeFill\Debug\ShapeFill.log”
1>ShapeFill- 1个错误,0个警告
========== 全部重新生成: 0 已成功, 1 已失败, 0 已跳过 ==========

此时可以通过两种方法解决:

解决方案:

第一步:将 项目——项目属性——配置属性——连接器——清单文件——嵌入清单 “是”改为“否”。若还不能解决问题进入第二步。

第二步:查看计算机是否为64bit操作系统,如是,继续如下操作。
查找是否有两个cvtres.exe。
…\vc\bin\cvtres.exe(VS2010的安装目录)
C:\Windows\Microsoft.NET\Framework\v4.0.30319\cvtres.exe
右键属性—详细信息, 查看两者版本号,删除/重命名较旧的版本。

第二种方法可以避免每次都需要进行设置。


运行成功,可是编译器提醒缺少MSVCR100D.dll,此时只需要在网上下载MSVCR100D.dll放到C:\Windows\SysWOW64(64位机器放在这个目录)下即可。

此时终于成功了!
这里写图片描述

接下来终于可以正式的开始DirectX11的学习了。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
不错的dx11入门教程 Tutorial 1: Setting up DirectX 11 with Visual Studio Tutorial 2: Creating a Framework and Window Tutorial 3: Initializing DirectX 11 Tutorial 4: Buffers, Shaders, and HLSL Tutorial 5: Texturing Tutorial 6: Diffuse Lighting Tutorial 7: 3D Model Rendering Tutorial 8: Loading Maya 2011 Models Tutorial 9: Ambient Lighting Tutorial 10: Specular Lighting Tutorial 11: 2D Rendering Tutorial 12: Font Engine Tutorial 13: Direct Input Tutorial 14: Direct Sound Tutorial 15: FPS, CPU Usage, and Timers Tutorial 16: Frustum Culling Tutorial 17: Multitexturing and Texture Arrays Tutorial 18: Light Maps Tutorial 19: Alpha Mapping Tutorial 20: Bump Mapping Tutorial 21: Specular Mapping Tutorial 22: Render to Texture Tutorial 23: Fog Tutorial 24: Clipping Planes Tutorial 25: Texture Translation Tutorial 26: Transparency Tutorial 27: Reflection Tutorial 28: Screen Fades Tutorial 29: Water Tutorial 30: Multiple Point Lights Tutorial 31: 3D Sound Tutorial 32: Glass and Ice Tutorial 33: Fire Tutorial 34: Billboarding Tutorial 35: Depth Buffer Tutorial 36: Blur Tutorial 37: Coming Soon... DirectX 10 Tutorials: Tutorial 1: Setting up DirectX 10 with Visual Studio Tutorial 2: Creating a Framework and Window Tutorial 3: Initializing DirectX 10 Tutorial 4: Buffers, Shaders, and HLSL Tutorial 5: Texturing Tutorial 6: Diffuse Lighting Tutorial 7: 3D Model Rendering Tutorial 8: Loading Maya 2011 Models Tutorial 9: Ambient Lighting Tutorial 10: Specular Lighting Tutorial 11: 2D Rendering Tutorial 12: Font Engine Tutorial 13: Direct Input Tutorial 14: Direct Sound Tutorial 15: FPS, CPU Usage, and Timers Tutorial 16: Frustum Culling Tutorial 17: Multitexturing and Texture Arrays Tutorial 18: Light Maps Tutorial 19: Alpha Mapping Tutorial 20: Bump Mapping Tutorial 21: Specular Mapping Tutorial 22: Render to Texture Tutorial 23: Fog Tutorial 24: Clipping Planes Tutorial 25: Texture Translation Tutorial 26: Transparency Tutorial 27: Reflection Tutorial 28: Screen Fades Tutorial 29: Water Tutorial 30: Multiple Point Lights Tutorial 31: 3D Sound Tutorial 32: Glass and Ice Tutorial 33: Fire Tutorial 34: Billboarding Tutorial 35: Depth Buffer Tutorial 36: Blur Tutorial 37: Coming Soon... DirectX 10 Terrain Tutorials: Tutorial 1: Grid and Camera Movement Tutorial 2: Height Maps Tutorial 3: Terrain Lighting Tutorial 4: Terrain Texturing Tutorial 5: Color Mapped Terrain Tutorial 6: Quad Trees Tutorial 7: Coming Soon... 。。。。。。。。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值