定义公用的函数方法 //d3dUtility.h ////////////////////////////////////////////////////////// // // File: d3dUtility.h // Author: hsg (c) All Rights Reserved // System: // 功能:提供通用函数 // ////////////////////////////////////////////////////////// #pragma once #ifndef __d3dUtility_H__ #define __d3dUtility_H__ #include <d3dx9.h> #include <d3d9.h> #include <string> #include <mmsystem.h> //定义名称空间d3d namespace d3d { //定义初始化函数InitD3D 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. //定义进入消息Loop函数EnterMsgLoop int EnterMsgLoop(bool (*ptr_display)(float timeDelta)); //定义窗体回调函数WndProc LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam); //定义模板函数Release(T t) template<class T> void Release(T t) { if(t) { t->Release(); t=0; } } //定义模板函数Delete(T t) template<class T> void Delete(T t) { if(t) { delete t; t=0; } } const D3DXCOLOR WHITE( D3DCOLOR_XRGB(255, 255, 255) ); const D3DXCOLOR BLACK( D3DCOLOR_XRGB( 0, 0, 0) ); const D3DXCOLOR RED( D3DCOLOR_XRGB(255, 0, 0) ); const D3DXCOLOR GREEN( D3DCOLOR_XRGB( 0, 255, 0) ); const D3DXCOLOR BLUE( D3DCOLOR_XRGB( 0, 0, 255) ); const D3DXCOLOR YELLOW( D3DCOLOR_XRGB(255, 255, 0) ); const D3DXCOLOR CYAN( D3DCOLOR_XRGB( 0, 255, 255) ); const D3DXCOLOR MAGENTA( D3DCOLOR_XRGB(255, 0, 255) ); } //类和结构 //---------------------------------------------- struct Vertex { Vertex(){} Vertex(float x, float y, float z) { _x = x; _y = y; _z = z; } float _x, _y, _z; static const DWORD FVF= D3DFVF_XYZ; }; //const DWORD VertexXYZ::FVF = D3DFVF_XYZ; //---------------------------------------------- struct ColorVertex { ColorVertex(){} ColorVertex(float x, float y, float z, D3DCOLOR c) { _x = x; _y = y; _z = z; _color = c; } float _x, _y, _z; D3DCOLOR _color; static const DWORD FVF= D3DFVF_XYZ | D3DFVF_DIFFUSE; }; //const DWORD ColorVertex::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE; #endif //__d3dUtility_H__