zfxd3dUtility.h
资源名称:Direct3D.rar [点击查看]
上传用户:junlon
上传日期:2022-01-05
资源大小:39075k
文件大小:3k
源码类别:
DirextX编程
开发平台:
Visual C++
- //--------------------------------------------------------------------------------------
- // 头文件: zfxd3dUtility.h , 作者:曾凡喜
- //
- // Direct3D程序初始化,主要完成主窗口创建,D3D设备创建任务
- //
- // 版权归作者所有,未经允许不得利用源代码进行任何商业活动
- //
- // 完成时间:2007-10-31
- //--------------------------------------------------------------------------------------
- #ifndef __zfxd3dUtility_H__
- #define __zfxd3dUtility_H__
- #include <d3dx9.h>
- // 该函数完成了注册窗口类、创建主窗口、创建设备等任务
- bool InitD3DApp(HINSTANCE hInstance, // 程序实例句柄
- bool windowed, // 布尔变量,是否为窗口模式
- D3DDEVTYPE deviceType, // HAL or REF
- IDirect3D9** pd3d9, // D3D对象接口
- IDirect3DDevice9** pd3dDevice,// D3D设备接口
- PCTSTR szTitle, // 窗口标题名
- int width = 640, int height = 480); // 窗口宽度和高度
- // 消息循环函数,该函数不应该在zfxd3dUtility.cpp中实现d3d9.lib d3dx9.lib winmm.lib
- LRESULT CALLBACK WndProc(
- HWND hwnd,
- UINT msg,
- WPARAM wParam,
- LPARAM lParam);
- #ifndef SAFE_DELETE
- #define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
- #endif
- #ifndef SAFE_DELETE_ARRAY
- #define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } }
- #endif
- #ifndef SAFE_RELEASE
- #define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
- #endif
- // 颜色定义
- 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) );
- // 灯光定义
- D3DLIGHT9 InitDirectionalLight(D3DXVECTOR3* direction, D3DXCOLOR* color);
- D3DLIGHT9 InitPointLight(D3DXVECTOR3* position, D3DXCOLOR* color);
- D3DLIGHT9 InitSpotLight(D3DXVECTOR3* position, D3DXVECTOR3* direction, D3DXCOLOR* color);
- bool InitDXFont(IDirect3DDevice9* pd3dDevice, ID3DXFont** pFont, PCTSTR szFontType,
- bool isItalic = true, int height = 15, int width = 8, int weight = 500);
- // 材质定义
- D3DMATERIAL9 InitMtrl(D3DXCOLOR a, D3DXCOLOR d, D3DXCOLOR s, D3DXCOLOR e, float p);
- const D3DMATERIAL9 WHITE_MTRL = InitMtrl(WHITE, WHITE, WHITE, BLACK, 2.0f);
- const D3DMATERIAL9 RED_MTRL = InitMtrl(RED, RED, RED, BLACK, 2.0f);
- const D3DMATERIAL9 GREEN_MTRL = InitMtrl(GREEN, GREEN, GREEN, BLACK, 2.0f);
- const D3DMATERIAL9 BLUE_MTRL = InitMtrl(BLUE, BLUE, BLUE, BLACK, 2.0f);
- const D3DMATERIAL9 YELLOW_MTRL = InitMtrl(YELLOW, YELLOW, YELLOW, BLACK, 2.0f);
- #endif //__zfxd3dUtility_H__