static bool InitializeDirectX( HWND hwnd ) { HRESULT hr; // Create the Direct3D interface object. d3d = Direct3DCreate9( D3D_SDK_VERSION ); Assert(d3d); // Get device capabilities D3DCAPS9 displayCaps; hr = d3d->GetDeviceCaps(0,D3DDEVTYPE_HAL,&displayCaps); Assert(hr==D3D_OK); // Get resolution of current display mode D3DDISPLAYMODE displayMode; hr = d3d->GetAdapterDisplayMode(0,&displayMode); Assert(hr==D3D_OK); DisplayHeight = displayMode.Height; DisplayWidth = displayMode.Width; if( DisplayHeight>DISPLAY_HEIGHT_MAX || DisplayWidth>DISPLAY_WIDTH_MAX ) { char buffer[200]; sprintf(buffer,"Display is too big (%dx%d).\n" "Please set your display to a 32-bit color mode no bigger than %dx%d.\n" "Then restart Seismic Duck.\n", DisplayWidth,DisplayHeight,DISPLAY_WIDTH_MAX,DISPLAY_HEIGHT_MAX); MessageBoxA(hwnd,buffer,NULL,MB_OK|MB_ICONWARNING); return false; } if( DisplayHeight<DISPLAY_HEIGHT_MIN || DisplayWidth<DISPLAY_WIDTH_MIN ) { char buffer[200]; sprintf(buffer,"Display is too small (%dx%d).\n" "Please set your display to a 32-bit color mode no smaller than %dx%d.\n" "Then restart Seismic Duck.\n", DisplayWidth,DisplayHeight,DISPLAY_WIDTH_MIN,DISPLAY_HEIGHT_MIN); MessageBoxA(hwnd,buffer,NULL,MB_OK|MB_ICONWARNING); return false; } // Create the device D3DPRESENT_PARAMETERS present; SetPresentParameters(present); hr = d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present, &Device ); if ( hr!=D3D_OK ) { char buffer[200]; sprintf(buffer,"Internal error: d3d->CreateDevice returned %s\n",Decode(hr)); MessageBoxA(hwnd,buffer,NULL,MB_OK|MB_ICONWARNING); return false; } return true; }
void HostSetFrameIntervalRate( int limit ) { D3DPRESENT_PARAMETERS present; SetPresentParameters(present); present.PresentationInterval = limit==0 ? D3DPRESENT_INTERVAL_IMMEDIATE : limit==1 ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_TWO; Device->Reset(&present); }
//Creates the direct3d interface void xDeviceManager::InitializeD3D(void) { #if DEBUG_LEVEL >= 1 if((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL) { LogWrite(LT_ERROR, "Could not create D3D Interface"); } #if DEBUG_LEVEL >= 3 LogWrite(LT_FUNCTION, "Created D3D Interface"); #endif #else g_pD3D = Direct3DCreate9(D3D_SDK_VERSION); #endif SetDefaultDisplayFormat(); SetPresentParameters(); #if DEBUG_LEVEL >= 1 if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &m_d3dpp, &g_pD3DDevice))) { LogWrite(LT_ERROR, "Failed to create D3D device"); } #if DEBUG_LEVEL >= 3 LogWrite(LT_FUNCTION, "Success in creating D3D device"); #endif #else g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &m_d3dpp, &m_pD3DDevice); #endif }