• Advertisement

Archived

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

Creating a screenshot

This topic is 5572 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
or try 1 as the swap chain instead of 0

Share this post


Link to post
Share on other sites
I''ve tried with swapchain 1 and the second parameter in
GetFrontBufferData is a pointer, not a dubble pointer, so
it doesn''t create the surface.

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

  • Advertisement