首页 > 代码库 > (转)配置vs2010的DirectX开发环境

(转)配置vs2010的DirectX开发环境


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,开发环境搞定,终于可以开始游戏开发了[DirectX] 使 Microsoft Visual Studio 2010 配置 DirectX 开发环境 - ㄨЮ音緣§華蒔 ̄ㄩ - ㄨЮ音緣§華蒔 ̄ㄩ。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 class	WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,		GetModuleHandle(NULL), NULL, NULL, NULL, NULL,		WINDOW_CLASS, NULL };	RegisterClassEx(&wc);	// Create the application‘s window	HWND hWnd = CreateWindow(WINDOW_CLASS, WINDOW_NAME, WS_OVERLAPPEDWINDOW,		100, 100, 640, 480, GetDesktopWindow(), NULL,		wc.hInstance, NULL);	g_D3D= Direct3DCreate9(D3D_SDK_VERSION);	//Initialize Direct3D	if(InitializeD3D(hWnd, false))	{		// Show the window		ShowWindow(hWnd, SW_SHOWDEFAULT);		UpdateWindow(hWnd);		// Enter the message loop		MSG msg;		ZeroMemory(&msg, sizeof(msg));		while(msg.message != WM_QUIT)		{			if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))			{				TranslateMessage(&msg);				DispatchMessage(&msg);			}			else				RenderScene();		}	}	// 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 D3DDevice	D3DPRESENT_PARAMETERS d3dpp;	ZeroMemory(&d3dpp, sizeof(d3dpp));	if(fullscreen)	{		d3dpp.Windowed = FALSE;		d3dpp.BackBufferWidth = 640;		d3dpp.BackBufferHeight = 480;	}	else		d3dpp.Windowed = TRUE;	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;	d3dpp.BackBufferFormat = displayMode.Format;	// Create the D3DDevice	if(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