int DDInit(void) { HRESULT hRet; hWnd = Form1->Handle; DDEnd(); hRet = DirectDrawCreateEx(NULL, (VOID**)&m_pDD, IID_IDirectDraw7, NULL); if(DDError(hRet != DD_OK,"DDCreateEX")) return(false); if (Form1->FullScreen) { hRet = m_pDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); hRet = m_pDD->SetDisplayMode(FScreen.Width, FScreen.Height, FScreen.Bpp,NULL,NULL); } else hRet = m_pDD->SetCooperativeLevel(hWnd, DDSCL_NORMAL); if(DDError(hRet != DD_OK,"DDSetCoop")) return(false); HRESULT hr; DDSURFACEDESC2 ddsd; ZeroMemory( &ddsd, sizeof( ddsd ) ); ddsd.dwSize = sizeof( ddsd ); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; if(DDError(hr = m_pDD->CreateSurface(&ddsd, &m_pddsFrontBuffer, NULL) ,"CreateFrontSurface")) return(false); // Create the backbuffer surface ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; ddsd.dwWidth = 1024; ddsd.dwHeight = 768; hr = m_pDD->CreateSurface(&ddsd, &m_pddsFrame, NULL); if (hr) { ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; ddsd.dwWidth = 460; ddsd.dwHeight = 400; hr = m_pDD->CreateSurface(&ddsd, &m_pddsFrame, NULL); if(DDError(hr,"CreateBackSurface")) return(false); tv.DisableAdvanced=1; } if (!Form1->FullScreen) { if(DDError(hr = m_pDD->CreateClipper(0, &pcClipper, NULL) ,"CreateClipper")) return(false); if(DDError(hr = pcClipper->SetHWnd(0, hWnd) ,"SetClipperHwnd")) { pcClipper->Release(); return(false); } if(DDError(hr = m_pddsFrontBuffer->SetClipper(pcClipper) ,"SetClipperSurface")) { pcClipper->Release(); return(false); } } return(true); }
////////////////////////////////////////////////////////////////////////////////// // CRMEngine CreateFullScreen - creates a full screen application ////////////////////////////////////////////////////////////////////////////////// HRESULT CRMEngine::CreateFullScreen(CDXScreen* pScreen, void *hWnd, int Width, int Height, int BPP) { GUID d3dGUID; LPDIRECTDRAW lpDD; LPDIRECTDRAWSURFACE lpDDS; HRESULT rval; CDXLOG("START: CRMEngine::CreateFullScreen"); CDXASSERT(BPP!=8); CDXLOG("Release any existing m_RMDevice we have"); // first release everything that has been allocated RELEASE(m_RMDevice); CDXLOG("Save our Screen Pointer, and switch us to FullScreen mode"); // create the CDXScreen object m_Screen = pScreen; if(FAILED(m_Screen->CreateFullScreen(hWnd, Width, Height, BPP))) { CDXLOG("FullScreen mode switch failed"); return D3DRMERR_NOTDONEYET; } #if DIRECTDRAW_VERSION >= CDX_DDVER CDXLOG("QueryInterface for a IDirectDraw Interface"); // query for a IDirectDraw object rval = m_Screen->GetDD()->QueryInterface(IID_IDirectDraw, (LPVOID*)&lpDD); if(rval != DD_OK) DDError(rval, NULL, __FILE__, __LINE__); CDXLOG("QueryInterface for a IDirectDrawSurface Interface"); rval = m_Screen->GetBack()->GetDDS()->QueryInterface(IID_IDirectDrawSurface, (LPVOID*)&lpDDS); if(rval != DD_OK) DDError(rval, NULL, __FILE__, __LINE__); #else CDXLOG("Save the DirectDraw and DirectDrawSurface pointers"); lpDD = m_Screen->GetDD(); lpDDS = m_Screen->GetBack()->GetDDS(); #endif CDXLOG("Attempt to CreateDeviceFromSurface"); // create the d3d device rval = m_Direct3DRM->CreateDeviceFromSurface(FindDevice(BPP, &d3dGUID), lpDD, lpDDS,0, &m_RMDevice); if(FAILED(rval)) { CDXLOG("Create attempt failed"); D3DError(rval, m_Screen->GetWindowHandle(), __FILE__, __LINE__); return D3DRMERR_NOTDONEYET; } CDXLOG("Set the RMDevice buffer count = 2"); /* in my doc it's specified that we should set this */ m_RMDevice->SetBufferCount(2); CDXLOG("Set our defaults based on bit depth"); // start our engine with default values based on color depth SetDefaults(); CDXLOG("END: CRMEngine::CreateFullScreen"); return D3DRM_OK; }