Jump to content
  • Advertisement
Sign in to follow this  
utilae

Can't 'print screen' in my app

This topic is 4996 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, I am using C++ and Direct3D9. In my app I used to be able to press 'print screen' and then quit out of the app and paste the screenshot into paint. Now all I get when I try print screen is a screenshot that is entirely green. Anyone got any ideas why it would do this? Is it something to do with my 2d ortho matrix ( D3DXMatrixOrthoOffCenterLH )?

Share this post


Link to post
Share on other sites
Advertisement
Since the window bound to the d3d device is drawn using hardware acceleration, there's no guarantee that the final rendered image is accessible to GDI at all. Matrices have nothing to do with this problem.

If you want to take a snapshot of the current d3d frame, see IDirect3DDevice9::GetFrontBufferData().

Share this post


Link to post
Share on other sites

void takeScreenShot(LPCTSTR pDestFile)
{
D3DDISPLAYMODE displayMode;

LPDIRECT3DSURFACE9 pd3dsFront = NULL;

// Get the display mode
pd3dDevice->GetDisplayMode(0, &displayMode);

// Create a surface to hold the front buffer
pd3dDevice->CreateOffscreenPlainSurface(displayMode.Width, displayMode.Height,
D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pd3dsFront, NULL);

// Get the front buffer and save it to a file
if( SUCCEEDED( pd3dDevice->GetFrontBufferData(0, pd3dsFront) ) )
D3DXSaveSurfaceToFile(pDestFile, D3DXIFF_BMP, pd3dsFront, NULL, NULL);

// Release the surface
if( pd3dsFront ) pd3dsFront->Release();
}

Share this post


Link to post
Share on other sites
It can be done without using GetFrontBufferData too. This will work with Direct3D and OpenGL. The only Direct3D code used is SetTransform for the high resolution screen shots.

|
|
|
V

Share this post


Link to post
Share on other sites
Here is the really simple code I use:


LPDIRECT3DSURFACE9 pSurf;
pd3dDevice->GetRenderTarget( 0, &pSurf );

D3DXSaveSurfaceToFile( L"screenshot.bmp", D3DXIFF_BMP, pSurf, NULL, NULL );
pSurf->Release();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!