home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Common / DXUT.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-28  |  9.9 KB  |  188 lines

  1. //--------------------------------------------------------------------------------------
  2. // File: DXUT.h
  3. //
  4. // DirectX SDK Direct3D sample framework
  5. //
  6. // Copyright (c) Microsoft Corporation. All rights reserved.
  7. //--------------------------------------------------------------------------------------
  8. #pragma once
  9. #ifndef DXUT_H
  10. #define DXUT_H
  11.  
  12. #ifndef UNICODE
  13. #error "The sample framework requires a Unicode build. If you are using Microsoft Visual C++ .NET, under the General tab of the project properties change the Character Set to 'Use Unicode Character Set'."
  14. #endif
  15.  
  16.  
  17. //--------------------------------------------------------------------------------------
  18. // Structs
  19. //--------------------------------------------------------------------------------------
  20. class CD3DEnumeration;
  21. class CD3DSettingsDlg;
  22.  
  23. struct DXUTDeviceSettings
  24. {
  25.     UINT AdapterOrdinal;
  26.     D3DDEVTYPE DeviceType;
  27.     D3DFORMAT AdapterFormat;
  28.     DWORD BehaviorFlags;
  29.     D3DPRESENT_PARAMETERS pp;
  30. };
  31.  
  32.  
  33. //--------------------------------------------------------------------------------------
  34. // Error codes
  35. //--------------------------------------------------------------------------------------
  36. #define DXUTERR_NODIRECT3D              MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0901)
  37. #define DXUTERR_NOCOMPATIBLEDEVICES     MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0902)
  38. #define DXUTERR_MEDIANOTFOUND           MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0903)
  39. #define DXUTERR_NONZEROREFCOUNT         MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0904)
  40. #define DXUTERR_CREATINGDEVICE          MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0905)
  41. #define DXUTERR_RESETTINGDEVICE         MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0906)
  42. #define DXUTERR_CREATINGDEVICEOBJECTS   MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0907)
  43. #define DXUTERR_RESETTINGDEVICEOBJECTS  MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0908)
  44. #define DXUTERR_INCORRECTVERSION        MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0909)
  45.  
  46.  
  47. //--------------------------------------------------------------------------------------
  48. // Callback registration 
  49. //--------------------------------------------------------------------------------------
  50. typedef bool    (CALLBACK *LPDXUTCALLBACKISDEVICEACCEPTABLE)( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, bool bWindowed );
  51. typedef void    (CALLBACK *LPDXUTCALLBACKMODIFYDEVICESETTINGS)( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps );
  52. typedef HRESULT (CALLBACK *LPDXUTCALLBACKDEVICECREATED)( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc );
  53. typedef HRESULT (CALLBACK *LPDXUTCALLBACKDEVICERESET)( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc );
  54. typedef void    (CALLBACK *LPDXUTCALLBACKDEVICEDESTROYED)();
  55. typedef void    (CALLBACK *LPDXUTCALLBACKDEVICELOST)();
  56. typedef void    (CALLBACK *LPDXUTCALLBACKFRAMEMOVE)( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime );
  57. typedef void    (CALLBACK *LPDXUTCALLBACKFRAMERENDER)( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime );
  58. typedef void    (CALLBACK *LPDXUTCALLBACKKEYBOARD)( UINT nChar, bool bKeyDown, bool bAltDown );
  59. typedef void    (CALLBACK *LPDXUTCALLBACKMOUSE)( bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown, bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta, int xPos, int yPos );
  60. typedef LRESULT (CALLBACK *LPDXUTCALLBACKMSGPROC)( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing );
  61. typedef void    (CALLBACK *LPDXUTCALLBACKTIMER)( UINT idEvent );
  62.  
  63. // Device callbacks
  64. void DXUTSetCallbackDeviceCreated( LPDXUTCALLBACKDEVICECREATED pCallbackDeviceCreated );
  65. void DXUTSetCallbackDeviceReset( LPDXUTCALLBACKDEVICERESET pCallbackDeviceReset );
  66. void DXUTSetCallbackDeviceLost( LPDXUTCALLBACKDEVICELOST pCallbackDeviceLost );
  67. void DXUTSetCallbackDeviceDestroyed( LPDXUTCALLBACKDEVICEDESTROYED pCallbackDeviceDestroyed );
  68.  
  69. // Frame callbacks
  70. void DXUTSetCallbackFrameMove( LPDXUTCALLBACKFRAMEMOVE pCallbackFrameMove );
  71. void DXUTSetCallbackFrameRender( LPDXUTCALLBACKFRAMERENDER pCallbackFrameRender );
  72.  
  73. // Message callbacks
  74. void DXUTSetCallbackKeyboard( LPDXUTCALLBACKKEYBOARD pCallbackKeyboard );
  75. void DXUTSetCallbackMouse( LPDXUTCALLBACKMOUSE pCallbackMouse, bool bIncludeMouseMove = false );
  76. void DXUTSetCallbackMsgProc( LPDXUTCALLBACKMSGPROC pCallbackMsgProc );
  77.  
  78.  
  79. //--------------------------------------------------------------------------------------
  80. // Initialization
  81. //--------------------------------------------------------------------------------------
  82. HRESULT DXUTInit( bool bParseCommandLine = true, bool bHandleDefaultHotkeys = true, bool bShowMsgBoxOnError = true );
  83.  
  84. // Choose either DXUTCreateWindow or DXUTSetWindow.  If using DXUTSetWindow, consider using DXUTStaticWndProc
  85. HRESULT DXUTCreateWindow( const WCHAR* strWindowTitle = L"Direct3D Window", 
  86.                           HINSTANCE hInstance = NULL, HICON hIcon = NULL, HMENU hMenu = NULL,
  87.                           int x = CW_USEDEFAULT, int y = CW_USEDEFAULT );
  88. HRESULT DXUTSetWindow( HWND hWndFocus, HWND hWndDeviceFullScreen, HWND hWndDeviceWindowed, bool bHandleMessages = true );
  89. LRESULT CALLBACK DXUTStaticWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
  90.  
  91. // Choose either DXUTCreateDevice or DXUTSetDevice or DXUTCreateDeviceFromSettings
  92. HRESULT DXUTCreateDevice( UINT AdapterOrdinal = D3DADAPTER_DEFAULT, bool bWindowed = true, 
  93.                           int nSuggestedWidth = 640, int nSuggestedHeight = 480,
  94.                           LPDXUTCALLBACKISDEVICEACCEPTABLE pCallbackIsDeviceAcceptable = NULL,
  95.                           LPDXUTCALLBACKMODIFYDEVICESETTINGS pCallbackModifyDeviceSettings = NULL );
  96. HRESULT DXUTCreateDeviceFromSettings( DXUTDeviceSettings* pDeviceSettings, bool bPreserveInput = false );
  97. HRESULT DXUTSetDevice( IDirect3DDevice9* pd3dDevice );
  98.  
  99. // Choose either DXUTMainLoop or implement your own main loop 
  100. HRESULT DXUTMainLoop( HACCEL hAccel = NULL );
  101.  
  102. // If not using DXUTMainLoop consider using DXUTRender3DEnvironment
  103. void DXUTRender3DEnvironment(); 
  104.  
  105.  
  106. //--------------------------------------------------------------------------------------
  107. // Finding valid device settings
  108. //--------------------------------------------------------------------------------------
  109. enum DXUT_MATCH_TYPE
  110. {
  111.     DXUTMT_IGNORE_INPUT = 0,  // Use the closest valid value to a default 
  112.     DXUTMT_PRESERVE_INPUT,    // Use input without change, but may cause no valid device to be found
  113.     DXUTMT_CLOSEST_TO_INPUT   // Use the closest valid value to the input 
  114. };
  115.  
  116. struct DXUTMatchOptions
  117. {
  118.     DXUT_MATCH_TYPE eAdapterOrdinal;
  119.     DXUT_MATCH_TYPE eDeviceType;
  120.     DXUT_MATCH_TYPE eWindowed;
  121.     DXUT_MATCH_TYPE eAdapterFormat;
  122.     DXUT_MATCH_TYPE eVertexProcessing;
  123.     DXUT_MATCH_TYPE eResolution;
  124.     DXUT_MATCH_TYPE eBackBufferFormat;
  125.     DXUT_MATCH_TYPE eBackBufferCount;
  126.     DXUT_MATCH_TYPE eMultiSample;
  127.     DXUT_MATCH_TYPE eSwapEffect;
  128.     DXUT_MATCH_TYPE eDepthFormat;
  129.     DXUT_MATCH_TYPE eStencilFormat;
  130.     DXUT_MATCH_TYPE ePresentFlags;
  131.     DXUT_MATCH_TYPE eRefreshRate;
  132.     DXUT_MATCH_TYPE ePresentInterval;
  133. };
  134.  
  135. HRESULT DXUTFindValidDeviceSettings( DXUTDeviceSettings* pOut, DXUTDeviceSettings* pIn = NULL, DXUTMatchOptions* pMatchOptions = NULL );
  136.  
  137.  
  138. //--------------------------------------------------------------------------------------
  139. // Common Tasks 
  140. //--------------------------------------------------------------------------------------
  141. void    DXUTSetCursorSettings( bool bShowCursorWhenFullScreen, bool bClipCursorWhenFullScreen );
  142. void    DXUTSetMultimonSettings( bool bAutoChangeAdapter );
  143. void    DXUTSetShortcutKeySettings( bool bAllowWhenFullscreen = false, bool bAllowWhenWindowed = true ); // Controls the Windows key, and accessibility shortcut keys
  144. void    DXUTSetConstantFrameTime( bool bConstantFrameTime, float fTimePerFrame = 0.0333f );
  145. void    DXUTSetShowSettingsDialog( bool bShow ); 
  146. HRESULT DXUTSetTimer( LPDXUTCALLBACKTIMER pCallbackTimer, float fTimeoutInSecs = 1.0f, UINT* pnIDEvent = NULL );
  147. HRESULT DXUTKillTimer( UINT nIDEvent );
  148. HRESULT DXUTToggleFullScreen();
  149. HRESULT DXUTToggleREF();
  150. void    DXUTPause( bool bPauseTime, bool bPauseRendering );
  151. void    DXUTResetFrameworkState();
  152. void    DXUTShutdown();
  153.  
  154.  
  155. //--------------------------------------------------------------------------------------
  156. // State Retrieval  
  157. //--------------------------------------------------------------------------------------
  158. IDirect3D9*             DXUTGetD3DObject(); // Does not addref unlike typical Get* APIs
  159. IDirect3DDevice9*       DXUTGetD3DDevice(); // Does not addref unlike typical Get* APIs
  160. DXUTDeviceSettings      DXUTGetDeviceSettings(); 
  161. D3DPRESENT_PARAMETERS   DXUTGetPresentParameters();
  162. const D3DSURFACE_DESC*  DXUTGetBackBufferSurfaceDesc();
  163. const D3DCAPS9*         DXUTGetDeviceCaps();
  164. HWND                    DXUTGetHWND();
  165. HWND                    DXUTGetHWNDFocus();
  166. HWND                    DXUTGetHWNDDeviceFullScreen();
  167. HWND                    DXUTGetHWNDDeviceWindowed();
  168. const RECT&             DXUTGetWindowClientRect();
  169. double                  DXUTGetTime();
  170. float                   DXUTGetElapsedTime();
  171. bool                    DXUTIsWindowed();
  172. float                   DXUTGetFPS();
  173. LPCWSTR                 DXUTGetWindowTitle();
  174. LPCWSTR                 DXUTGetFrameStats();
  175. LPCWSTR                 DXUTGetDeviceStats();
  176. bool                    DXUTGetShowSettingsDialog(); 
  177. bool                    DXUTIsRenderingPaused();
  178. bool                    DXUTIsTimePaused();
  179. int                     DXUTGetExitCode();
  180. bool                    DXUTIsKeyDown( BYTE vKey ); // Pass a virtual-key code, ex. VK_F1, 'A', VK_RETURN, VK_LSHIFT, etc
  181. bool                    DXUTIsMouseButtonDown( BYTE vButton ); // Pass a virtual-key code: VK_LBUTTON, VK_RBUTTON, VK_MBUTTON, VK_XBUTTON1, VK_XBUTTON2
  182.  
  183. #endif
  184.  
  185.  
  186.  
  187.  
  188.