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();
Creating a screenshot
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?
// 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();
}
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();
}
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
maybe try not using CreateOffscreenPlainSurface
maybe the GetFrontBufferData creates the surface now
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.
GetFrontBufferData is a pointer, not a dubble pointer, so
it doesn''t create the surface.
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
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
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
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
I think I had the same problem. I simply solved it by using GetBackBuffer instead and get it before Presenting. Then save the surface. Easy as that.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement