void CSnapShot::GetFrontBufferPixels(UINT uiSizeX, UINT uiSizeY,unsigned char* buffer) { // Get our d3d device IDirect3DDevice9 * pDevice = g_pCore->GetGraphics()->GetDevice(); // Get our display mode D3DDISPLAYMODE displayMode; pDevice->GetDisplayMode(0, &displayMode); // Create our surface IDirect3DSurface9 * pSurface = nullptr; pDevice->CreateOffscreenPlainSurface(displayMode.Width, displayMode.Height, SCREEN_SHOT_FORMAT, D3DPOOL_SCRATCH, &pSurface, nullptr); if(pSurface) { pDevice->GetFrontBufferData(0, pSurface); // Create the client rect RECT clientRect; { POINT clientPoint; clientPoint.x = 0; clientPoint.y = 0; ClientToScreen(*(HWND *)COffsets::VAR_HWnd, &clientPoint); clientRect.left = clientPoint.x; clientRect.top = clientPoint.y; clientRect.right = (clientRect.left + displayMode.Width); clientRect.bottom = (clientRect.top + displayMode.Height); } D3DLOCKED_RECT lockedRect; HRESULT hr = pSurface->LockRect(&lockedRect, NULL, D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK | D3DLOCK_DONOTWAIT); if(SUCCEEDED(hr)) { void* pBits = lockedRect.pBits; UINT ms_ulPitch = lockedRect.Pitch; for(unsigned int i = 0; i < displayMode.Height; ++i) memcpy(buffer + (displayMode.Width * 4) * i, (BYTE*)pBits + i * ms_ulPitch, (displayMode.Width * 4)); } pSurface->UnlockRect(); pSurface->Release(); } }
D3DDISPLAYMODE const sge::d3d9::devicefuncs::get_display_mode( IDirect3DDevice9 &_device, UINT const _swap_chain ) { D3DDISPLAYMODE ret; if( _device.GetDisplayMode( _swap_chain, &ret ) != D3D_OK ) throw sge::renderer::exception( FCPPT_TEXT("GetDisplayMode failed!") ); return ret; }