Jump to content
  • Advertisement


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


Windowed Screenshots in DX 9

This topic is 5200 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

I''ve succesfully used GetFrontBufferData(...) to get a full screen screenshot. I''d like to set my program up to also be capable of taking windowed screenshots. How should I do that? Thanks

Share this post

Link to post
Share on other sites
If you''re using D3DX, their SaveSurfaceToFile function
can be passed the rectangle to save from the surface. Use
your window''s rectangle.

Share this post

Link to post
Share on other sites
This is what i use for the full screen shots. I understand that the window''s rect can be used as the last parameter in D3DXSaveSurfaceToFile, but what do I do as far ss the SrcSurface goes since I can''t use GetFrontBufferData?


void CMain::TakeScreenShot()//, int screenx, int screeny)

char file_name[40];
FILE* f;
for(int i=0;i<999;i++)
// build the filename

sprintf(file_name, "Screenshots\\Buzzster%i.jpg\0", i);
f = fopen(file_name, "r");
if( f == NULL)
fclose( f );

LPDIRECT3DSURFACE9 frontbuf=NULL;//buffer to store copy of front buffer

//Creates the offscreen surface

m_pD3DDevice->CreateOffscreenPlainSurface(640, 480, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &frontbuf, NULL);

//Copy the front buffer into the surface

HRESULT hr = m_pD3DDevice->GetFrontBufferData(NULL, frontbuf);

//error checking

if(hr != D3D_OK)
//do error handling etc...

Log("Could not take screenshot.\n");
frontbuf->Release(); //release the surface so there is no memory leak


//Writes the image to a file

//the last 2 params are NULL because we want the entire front buffer and no palette

D3DXSaveSurfaceToFile(file_name, D3DXIFF_JPG, frontbuf, NULL, NULL);

//release the surface so there is no memory leak


Share this post

Link to post
Share on other sites
I don''t understand your problem..?

If your code currently saves the entire screen correctly, just
pass your window''s client area as the rectangle. D3DX will cut
that rectangle out of your surface and save it alone to file.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!