🔒 Locked
screen shot code
Advertisement
Original Post
im trying to take screen shots in my engine, it works fine fullscreen, but in window mode it doesnt work:
[cpp]
if( SUCCEEDED( GetDevice()->GetDevice()->GetBackBuffer(0,0, D3DBACKBUFFER_TYPE_MONO, &src) ) )
{
retval = D3DXSaveSurfaceToFile(buffer, D3DXIFF_BMP, src, NULL,NULL);
//retval = D3DXSaveSurfaceToFile(buffer, D3DXIFF_JPG, src, NULL,NULL);
}
else
{
ENGINE.GetConsole()->Error( __FILE__, __LINE__, "Failed to take screen shot");
}
[/cpp]
also you can see the line commented out, i would like to to save the image as a jpg if possible, but when i open it the dimensions are wrong, as the bottom part of the image is missing.
any ideas?
Here is my code, hope this helps:
[edited by - ataru on January 6, 2004 11:17:15 AM]
HRESULT MYCLASS::saveScreenShot(char *fileName, D3DXIMAGE_FILEFORMAT format)
{
HRESULT hr;
LPDIRECT3DSURFACE9 buffer = NULL; //The front buffer used to get the screenshot
// Create a surface for the screenshot to be rendered to
if( FAILED( hr = g_pDevice->CreateOffscreenPlainSurface( screenSizeX, screenSizeY,
D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &buffer, NULL ) ) )
return hr;
// Write the front buffer to the surface
if (!fullScreen)
{
if (FAILED (hr = g_pDevice->GetRenderTarget( 0, &buffer )))
{
gLOG("ERROR FRONT BUFFER AQUASITION FAILED\n");
//do error handling etc...
buffer->Release();
return hr;
}
}
else
{
if( FAILED( hr = g_pDevice->GetFrontBufferData( 0, buffer ) ) )
{
gLOG("ERROR FRONT BUFFER AQUASITION FAILED\n");
//do error handling etc...
buffer->Release();
return hr;
}
}
D3DXSaveSurfaceToFile( fileName, format, buffer, NULL, NULL );
// Cleanup
buffer->Release();
return D3D_OK;
}
[edited by - ataru on January 6, 2004 11:17:15 AM]
Supagu, JPG saving is definately broken in the DX9 SDK. I''m not sure if they fixed that in the winter/summer update that just happened not all that long ago.
I''d save it as a TGA or BMP, and then use __________ to convert it to JPEG. Can''t trust DX to do a good job of compressing the files, anyway. Doing it by hand I can generally get a %20-%30 space savings. (And if that blank equals Photoshop, you can batch this in order to process large runs of screenshots.)
---
[[ Gaping Wolf Software ]] [[ GameGenesis Forums ]]
I''d save it as a TGA or BMP, and then use __________ to convert it to JPEG. Can''t trust DX to do a good job of compressing the files, anyway. Doing it by hand I can generally get a %20-%30 space savings. (And if that blank equals Photoshop, you can batch this in order to process large runs of screenshots.)
---
[[ Gaping Wolf Software ]] [[ GameGenesis Forums ]]
okay, bmp is fine.
i tried your code ataru, but the code still failes on D3DXSaveSurfaceToFile, i tried changing D3DFMT_A8R8G8B8 to D3DFMT_R8G8B8 which would be more suited to bitmaps, but still crashes :-/
would be nice to be able to output the stencil buffer to a file also for debugging
[edited by - supagu on January 6, 2004 10:49:28 PM]
i tried your code ataru, but the code still failes on D3DXSaveSurfaceToFile, i tried changing D3DFMT_A8R8G8B8 to D3DFMT_R8G8B8 which would be more suited to bitmaps, but still crashes :-/
would be nice to be able to output the stencil buffer to a file also for debugging
[edited by - supagu on January 6, 2004 10:49:28 PM]
quote:
would be nice to be able to output the stencil buffer to a file also for debugging
You are able to access the stencil buffer with this method:
m_D3DDevice->GetDepthStencilSurface()
You cant read from the back buffer. There is an IDirect3D function to get the front buffer though. I makes a copy in system memory
Don''t forget to Release() the pointer to the surface when you are done
PNG files are probably the best bet since they have lossless compression and are well accepted
Don''t forget to Release() the pointer to the surface when you are done
PNG files are probably the best bet since they have lossless compression and are well accepted
Use the Debug dll''s and run dbMon maybe that will telll you what the invalid parameters are. That code I posted has one bug, for some reason the release does not really work, and after 100 or so screenshots it fails. I solved it by moving the buffer variable to be a class member, and create it only once. Maybe that will help.
But it looks like you can''t even save 1, so that''s strange. Are you saving as .bmp? That code should work for .bmp.
Make sure you are setting fullscreen to false.
But it looks like you can''t even save 1, so that''s strange. Are you saving as .bmp? That code should work for .bmp.
Make sure you are setting fullscreen to false.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement