//---------------------------------------运行DirectX程序配置环境VS2010-------------------------------
D:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86;(项目属性—VC++目录—库目录)
D:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include;(项目属性—VC++目录—包含目录)
d3d9.lib;d3dx9.lib;winmm.lib;(项目属性—链接器—输入)
//-----------------------------------------------------------------------------------------
#include<windows.h>
#include <stdio.h>#include "d3dx9.h" //Driect9.0的头文件
#include<string>
#pragma comment(lib,"Msimg32.lib")
#pragma comment(lib,"winmm.lib")
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
#define WINDOW_TITLE "Directx9.0游戏窗口"
#define WINDOW_ICON L"icon.ico"
#define WINDOW_CLASSNAME "GameTest"
IDirect3D9 *_d3d9=0; //声明Direct接口指针
D3DCAPS9 caps;//接口性能结构
D3DDEVTYPE devicetype;//设备类型
D3DPRESENT_PARAMETERS d3dpp; //D3D参数结构
IDirect3DDevice9 *device=0; //DirectDevice接口
WNDCLASSEX wndClass={0};
IDirect3DVertexBuffer9 *VB=0;//顶点缓存对象指针
IDirect3DIndexBuffer9 *IB=0;//索引缓存对象指针
struct Vertex{
Vertex(){}
Vertex(float x,float y,float z,float nx,float ny,float nz){
_x=x;
_y=y;
_z=z;
normal.x=nx;
normal.y=ny;
normal.z=nz;
//_color=color;
}
float _x,_y,_z;
D3DXVECTOR3 normal;
//DWORD _color;
static const WORD FVF;
};
const WORD Vertex::FVF=(D3DFVF_XYZ|D3DFVF_NORMAL);
bool D3D_Setup(); //初始化顶点缓存
void Init_D3D(HWND hwnd);//初始化Direct
void Clean_D3D();//清除释放设备
bool Dispaly_D3D(); //显示
void Fill_Directparam(HWND hwnd);
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam);//窗口回调函数
BOOL RegisterClass(HINSTANCE hInstance); //注册窗口类
HWND InitInstance(HINSTANCE hInstance,int nShowCmd); //初始化程序实例
/
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
if(!RegisterClass(hInstance)) exit(0);
HWND hWnd;
if(!(hWnd=InitInstance(hInstance,nShowCmd))) exit(0);
Init_D3D(hWnd);
D3D_Setup();
MSG msg;
ZeroMemory(&msg,sizeof(msg));
while(msg.message!=WM_QUIT)
{
if(PeekMessage(&msg,0,0,0,PM_REMOVE))
{
TranslateMessage(&msg);//把虚拟按键转换成字符消息
DispatchMessage(&msg);//分发消息给窗口
}
else
{
Dispaly_D3D();
}
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
switch(message)
{
//case WM_PAINT:
// Dispaly_D3D();
// ValidateRect(hwnd,NULL);
// break;
case WM_KEYDOWN:
if(wparam==VK_ESCAPE) <