Sign in to follow this  

Making a screenshot?

This topic is 3726 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 guys, i have a question. How do i make a screenshot from a directX application in fullscreen. For example in some games if you click the print button they make a screenshot for you and save it as a bitmap. Is there a easy solution for this or are 1000 lines required? If nobody knows this another question is, if im in game in fullscreen and, i click print and paste it into paint it works most time. I only get problems if something in the game is animated, e.g. particle systems, skinned meshes then the screenshot in paint is just a pink screen. Does anybody know why this happens?

Share this post


Link to post
Share on other sites
Here it is



static int g_uNumScreenshots = 0;

void makeScreenshot(D3DXIMAGE_FILEFORMAT format)
{

//D3DDISPLAYMODE d3ddm;
IDirect3DSurface9 *pScreenshot = NULL;
static int g_uNumScreenshots = 0;

static LPDIRECT3DSWAPCHAIN9 pSwapChain = NULL; // aktualis swapchain
static LPDIRECT3DSURFACE9 pBackBuffer = NULL; // aktualis hatter buffer

m_pd3dDevice->GetSwapChain( 0, &pSwapChain );
m_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pScreenshot );

TCHAR szScreenshot[32];
sprintf( szScreenshot, "ScreenShot%.2dD.jpg", g_uNumScreenshots );
if(FAILED(D3DXSaveSurfaceToFile( szScreenshot, (D3DXIMAGE_FILEFORMAT)format, pScreenshot, NULL, NULL )))
{
//error
}

SAFE_RELEASE( pScreenshot );

m_pd3dDevice->GetBackBuffer( 1, 0, D3DBACKBUFFER_TYPE_MONO, &pScreenshot );


sprintf( szScreenshot, "ScreenShot%.2dU.jpg", g_uNumScreenshots++ );
if(FAILED(D3DXSaveSurfaceToFile( szScreenshot, format, pScreenshot, NULL, NULL )))
{
// error
}
//Sleep(100);
SAFE_RELEASE( pScreenshot );



}



Share this post


Link to post
Share on other sites
You need to call streamer's makeScreenshot function after EndScene() and before Present(), otherwise the backbuffer gets swapped to the frontbuffer, and the backbuffer gets filled with rubbish - the debug rumtimes enforce this for you top stop you making mistakes.

Share this post


Link to post
Share on other sites
Quote:
Original post by legalize
Quote:
Original post by streamer
Here it is


Good god man, please learn how to use std::string!


Well yeah [smile] you're right! I know to use it, but I got used to this bad kind of programming.

Share this post


Link to post
Share on other sites
And I forgot to notice that function above is made for program that use 2 monitor.

Here is one monitor version:



static int g_uNumScreenshots = 0;
void makeScreenshot(D3DXIMAGE_FILEFORMAT format)
{
D3DDISPLAYMODE d3ddm;
IDirect3DSurface9 *pScreenshot = NULL;
static int g_uNumScreenshots = 0;
m_pd3dDevice->GetDisplayMode( 0, &d3ddm );

m_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pScreenshot );

TCHAR szScreenshot[32];
sprintf( szScreenshot, "ScreenShot%.2d.png", g_uNumScreenshots++ );
if(FAILED(D3DXSaveSurfaceToFile( szScreenshot, format, pScreenshot, NULL, NULL )))
{
// error
}

SAFE_RELEASE( pScreenshot );

}

Share this post


Link to post
Share on other sites

This topic is 3726 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this