1、安装directx sdk
安装包:
解压:
2、创建C++控制台应用程序
3、导入头文件和源文件
注:在x86解决方案下进行调试!!!!!
4、添加包含目录和库目录
配置属性——VC++目录
包含目录:D:\Software Install\D3D_SDK\Include(根据自己解压的文件夹目录,选择Include文件夹路径)
库目录:D:\Software Install\D3D_SDK\Lib\x86(选择x86文件夹路径)
5、修改字符集
配置属性——高级——字符集
6、添加依赖项
配置属性——链接器——输入——附加依赖项
d3d9.lib
d3dx9d.lib
d3dx10d.lib
dxerr.lib
dxguid.lib
winmm.lib
comctl32.lib
7、将系统更改为窗口
配置属性——链接器——系统——子系统
8、结果展示
9、代码
(1)d3dUtility.h文件
//
//
// File: d3dUtility.h
//
// Author: Frank Luna (C) All Rights Reserved
//
// System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0
//
// Desc: Provides utility functions for simplifying common tasks.
//
//
#ifndef __d3dUtilityH__
#define __d3dUtilityH__
#include <d3dx9.h>
#include <string>
namespace d3d
{
bool InitD3D(
HINSTANCE hInstance, // [in] Application instance.
int width, int height, // [in] Backbuffer dimensions.
bool windowed, // [in] Windowed (true)or full screen (false).
D3DDEVTYPE deviceType, // [in] HAL or REF
IDirect3DDevice9** device);// [out]The created device.
int EnterMsgLoop(
bool (*ptr_display)(float timeDelta));
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam);
template<class T> void Release(T t)
{
if( t )
{
t->Release();
t = 0;
}
}
template<class T> void Delete(T t)
{
if( t )
{
delete t;
t = 0;
}
}
}
#endif // __d3dUtilityH__
(2)d3dUtility.cpp文件
//
//
// File: d3dUtility.cpp
//
// Author: Frank Luna (C) All Rights Reserved
//
// System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0
//
// Desc: Provides utility functions for simplifying common tasks.
//
//
#include "d3dUtility.h"
bool d3d::InitD3D(
HINSTANCE hInstance,
int width, int height,
bool windowed,
D3DDEVTYPE deviceType,
IDirect3DDevice9** device)
{
//