screen shot code

Started by
10 comments, last by supagu 20 years, 3 months ago
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?
Advertisement
Here is my code, hope this helps:

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 ]]
--- - 2D/Pixel Artist - 3D Artist - Game Programmer - Ulfr Fenris[[ 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]
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()
supagu = I just used his code and it works flawlessly with PNG''s.
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/
For some reason though I tried to output the stencil buffer to a png file using the same surface to file method as before into png format and it fails when exporting the file. Perhaps this has something to do with your same problem supagu.
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/
Sorry, have not gotten back to this thread for a while. I''ve tested this on windowed and non-windowed modes for .bmp I assumed other formats would work if you change the settings.

Did you the debug output?
Yes I the debug outputted. (Sorry I have no idea what you''re talking about)
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/
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

This topic is closed to new replies.

Advertisement