Jump to content
  • Advertisement
Sign in to follow this  
Crow-knee

Screenshot code

This topic is 4937 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 All, I have just spent the last hour our so working out how to take a screenshot. It's easy enough, but I wanted to be able to do it from within my game object code, so I had no direct access to the windows stuff. So for those of you who are interested, here is a snippet of code to take a screen show with only querying your DX device...
bool c_Game::Take_Screenshot(IDirect3DDevice8 *d3dd) {
	DebugPrint(false, ("Taking screenshot.\n"));
	
	D3DDISPLAYMODE dm;
	if (FAILED(d3dd->GetDisplayMode(&dm))) {
		ErrorPrint(false, ("GetDisplayMode failed.\n"));
		return false;
	}

	D3DDEVICE_CREATION_PARAMETERS dcp;
	if (FAILED(d3dd->GetCreationParameters(&dcp))) {
		ErrorPrint(false, ("GetCreationParameters failed.\n"));
		return false;
	}
	RECT rect;
	POINT pnt;
	GetClientRect(dcp.hFocusWindow, &rect);
	pnt.x = 0;
	pnt.y = 0;
	ClientToScreen(dcp.hFocusWindow, &pnt);
	rect.left += pnt.x;
	rect.right += pnt.x;
	rect.top += pnt.y;
	rect.bottom += pnt.y;
	
	IDirect3DSurface8 *surfFront;
	if (FAILED(d3dd->CreateImageSurface(dm.Width, dm.Height, D3DFMT_A8R8G8B8, &surfFront))) {
		ErrorPrint(false, ("CreateImageSurface failed.\n"));
		return false;
	}
	if (FAILED(d3dd->GetFrontBuffer(surfFront))) {
		ErrorPrint(false, ("GetFrontBuffer failed.\n"));
		return false;
	}
	if (FAILED(D3DXSaveSurfaceToFile("screen.bmp", D3DXIFF_BMP, surfFront, NULL, &rect))) { //NULL))) {
		ErrorPrint(false, ("SaveSurface failed.\n"));
		return false;
	}
	SafeRelease(surfFront);
	return true;
}

Hope this helps, Steele. Edit : Just wrapped it up into a procedure. [Edited by - Crow-knee on December 13, 2004 10:38:39 PM]

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!