(轉)配置vs2010的DirectX開發環境

來源:互聯網
上載者:User

標籤:des   blog   http   color   使用   os   io   strong   


1>建立項目.由於vs2010隻能配置單個項目的DirectX環境,所以我們需要先建立項目.
2>開啟項目屬性頁面.vs2010->功能表列->視圖->屬性管理員->右鍵需要配置DirectX環境的項目->屬性。
3〉加入DirectX路徑。左邊“配置屬性”-〉vc++目錄,如:
#. 添加“$(DXSDK_DIR)Utilities/Bin/x86”(不包括雙引號)到 “可執行檔目錄”;

#. 添加“$(DXSDK_DIR)Include”(不包括雙引號)到 “包含目錄”;

#. 添加“$(DXSDK_DIR)Lib/x86”(不包括雙引號)到 “庫目錄”;

#其他的地方 比如c/c++ 連結器裡面都不用添加了,只是在這裡面的vc++目錄裡面添加即可,此外還要再常規裡面將字元集設定為使用多位元組字元集,若是設定為了unicode之後會出錯。如下:(原因不知道)

注意:如果是製作64位的遊戲,添加的是“$(DXSDK_DIR)Lib/x64”(不包括雙引號)到 “庫目錄”,其他不變.

        OK,開發環境搞定,終於可以開始遊戲開發了。Enjoying!!

貼一個官網協助文檔的安裝說明(E文):

Install the DirectX SDK 
        After installing the DirectX SDK, before building a project in Visual Studio, you must initialize the directories in Visual Studio by doing the following:

        Select Tools -> Options -> Projects and Solutions -> VC++ Directories

              Show Executable files and add: $(DXSDK_DIR)Utilities/Bin/x86

              Show Include files and add: $(DXSDK_DIR)Include

              Show Library files and add: $(DXSDK_DIR)Lib/x86

              Show Library files (for x64 targets) and add: $(DXSDK_DIR)Lib/x64

Note 
        For VS 2010 there is no longer a global VC++ Directories setting. This information should be present in each Visual Studio project file to reference the DirectX SDK.

 

上一段測試代碼:

#include <d3d9.h>#include <Windows.h>#pragma comment(lib, "d3d9.lib")#pragma comment(lib, "d3dx9.lib")#define WINDOW_CLASS "UGPDX"#define WINDOW_NAME  "Blank D3D Window"// Function Prototypes...bool InitializeD3D(HWND hWnd, bool fullscreen);void RenderScene();void Shutdown();// Direct3D object and device.LPDIRECT3D9 g_D3D = NULL;LPDIRECT3DDEVICE9 g_D3DDevice = NULL;LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){switch(msg){case WM_DESTROY:PostQuitMessage(0);return 0;break;case WM_KEYUP:if(wParam == VK_ESCAPE) PostQuitMessage(0);break;}return DefWindowProc(hWnd, msg, wParam, lParam);}int WINAPI WinMain(HINSTANCE hInst, HINSTANCE prevhInst, LPSTR cmdLine, int show){// Register the window classWNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,GetModuleHandle(NULL), NULL, NULL, NULL, NULL,WINDOW_CLASS, NULL };RegisterClassEx(&wc);// Create the application‘s windowHWND hWnd = CreateWindow(WINDOW_CLASS, WINDOW_NAME, WS_OVERLAPPEDWINDOW,100, 100, 640, 480, GetDesktopWindow(), NULL,wc.hInstance, NULL);g_D3D= Direct3DCreate9(D3D_SDK_VERSION);//Initialize Direct3Dif(InitializeD3D(hWnd, false)){// Show the windowShowWindow(hWnd, SW_SHOWDEFAULT);UpdateWindow(hWnd);// Enter the message loopMSG msg;ZeroMemory(&msg, sizeof(msg));while(msg.message != WM_QUIT){if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)){TranslateMessage(&msg);DispatchMessage(&msg);}elseRenderScene();}}// Release any and all resources.Shutdown();// Unregister our window.UnregisterClass(WINDOW_CLASS, wc.hInstance);return 0;}bool InitializeD3D(HWND hWnd, bool fullscreen){D3DDISPLAYMODE displayMode;//Create the D3D object.g_D3D = Direct3DCreate9(D3D_SDK_VERSION);if(g_D3D == NULL) return false;// Get the desktop display mode.if(FAILED(g_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode)))return false;// Set up the structure used to create the D3DDeviceD3DPRESENT_PARAMETERS d3dpp;ZeroMemory(&d3dpp, sizeof(d3dpp));if(fullscreen){d3dpp.Windowed = FALSE;d3dpp.BackBufferWidth = 640;d3dpp.BackBufferHeight = 480;}elsed3dpp.Windowed = TRUE;d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;d3dpp.BackBufferFormat = displayMode.Format;// Create the D3DDeviceif(FAILED(g_D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_D3DDevice))){return false;}return true;}void RenderScene(){// Clear the backbuffer.g_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);// Begin the scene.  Start rendering.g_D3DDevice->BeginScene();// End the scene.  Stop rendering.g_D3DDevice->EndScene();// Display the scene.g_D3DDevice->Present(NULL, NULL, NULL, NULL);}void Shutdown(){if(g_D3DDevice != NULL) g_D3DDevice->Release();if(g_D3D != NULL) g_D3D->Release();}

  運行可以看到視窗。ok

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.