Archived

This topic is now archived and is closed to further replies.

Lazy303

Creating a screenshot

Recommended Posts

Hi! This code doesn''t work.I get a D3DERR_INVALIDCALL when calling GetFrontBufferData. I have no idea what the first parameter in GetFrontBufferData should be. Does anyone know what could be wrong?
  
LPDIRECT3DSURFACE9 pFrontBuffer;   
pD3DDevice->CreateOffscreenPlainSurface(iWidth, iHeight, D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT, &pFrontBuffer,NULL);

pD3DDevice->GetFrontBufferData(0,pFrontBuffer);

D3DXSaveSurfaceToFile(szFileName, D3DXIFF_BMP, pFrontBuffer, NULL, NULL);

pFrontBuffer->Release();
  

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
// taken from an article at gamedev.net

void TakeScreenShot(IDirect3DDevice8* device, char* file_name, int screenx, int screeny)
{
IDirect3DSurface8* frontbuf; //this is our pointer to the memory location containing our copy of the
//front buffer

//now we create the image that our screen shot will be copied into
//NOTE: Surface format of the front buffer is D3DFMT_A8R8G8B8 when it is returned
device->CreateImageSurface(screenx, screeny, D3DFMT_A8R8G8B8, &frontbuf);

//now we copy the front buffer into our surface
HRESULT hr = device->GetFrontBuffer(frontbuf);

//error checking
if(hr != D3D_OK)
{
//do error handling etc...
frontbuf->Release(); //release the surface so there is no memory leak
return;
}

//now write our screen shot to a bitmap file
//the last 2 params are NULL because we want the entire front buffer and no palette
D3DXSaveSurfaceToFile(file_name, D3DXIFF_BMP, frontbuf, NULL, NULL);

//release the surface so there is no memory leak
frontbuf->Release();
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
what you have looks right according to the way it was done with dx8.

maybe try not using CreateOffscreenPlainSurface

maybe the GetFrontBufferData creates the surface now

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
wait I think I know.

try D3DPOOL_SYSTEMMEM instead of D3DPOOL_DEFAULT

IDirect3DDevice9::GetFrontBufferData Method.
Generates a copy of the device''s front buffer and places that copy in a SYSTEM memory buffer provided by the application

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
wait I think I may have figured it out.

try D3DPOOL_SYSTEMMEM instead of D3DPOOL_DEFAULT

IDirect3DDevice9::GetFrontBufferData Method.
Generates a copy of the device''s front buffer and places that copy in a SYSTEM memory buffer provided by the application

Share this post


Link to post
Share on other sites
What you''ve got looks correct, minus the pool - you should be using system memory. I have pretty much the same thing in C# and DX9 and mine works. I can offer two theories:

- Are you trying to take this screenshot in full screen or windowed mode? If windowed, are you sure your width and height values match up with the size of your window? Example: Window size is 640x480, but your variables read 656 and 497 or something close to 640x480, but not equal. Try taking your screenshot in full screen mode, it''ll work then. Or if windowed, recalculate your width/height variables to account for the client area and window borders.

- Are you calling this code AFTER the Device.Present() command?


Current Projects:
- Ariene GE (90%): Released as beta.

Share this post


Link to post
Share on other sites