码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-08-13 12:18:16      阅读:315      评论:0      收藏:0      [点我收藏+]

标签: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之后会出错。如下:(原因不知道)

bubuko.com,布布扣

注意:如果是制作64位的游戏,添加的是“$(DXSDK_DIR)Lib/x64”(不包括双引号)到 “库目录”,其他不变.

        OK,开发环境搞定,终于可以开始游戏开发了bubuko.com,布布扣。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

(转)配置vs2010的DirectX开发环境,布布扣,bubuko.com

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

标签:des   blog   http   color   使用   os   io   strong   

原文地址:http://www.cnblogs.com/tiancun/p/3909458.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!