Skip to main content
GameDev.net gamedev.net
🔒 Locked

C# & XNA - How can I take a screenshot of what I have already drawn to the screen...

Started by afsd42 Jun 6, 2009 at 10:36 PM 1 replies 3.2k views
Original Post
afsd42
afsd42
What I want to do is have my game draw itself as normal. When the user is about to open the menu, I want it to take a screenshot of the game area. I then want to draw this image in black and white or something funky while my menu is drawn over top of it. Basically, I don't feel like having my game draw everything over and over if I don't have to.
cyansoft
cyansoft
First create a ResolveTexture2D in your game's LoadContent method:

renderTargetTexture = new ResolveTexture2D(        graphics.GraphicsDevice,        graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,        graphics.GraphicsDevice.PresentationParameters.BackBufferHeight, 1,        graphics.GraphicsDevice.PresentationParameters.BackBufferFormat);


Then resolve the back buffer in your Draw method after you draw your scene:
graphics.GraphicsDevice.ResolveBackBuffer(renderTargetTexture);


Finally, draw your captured back buffer using a spritebatch when your game is paused in your Draw method:
spriteBatch.Draw(renderTargetTexture, Vector2.Zero, Color.White);


If you want the image to be grayscale, you'll need to write a pixel shader and load it with an effect file in your LoadContent, then set the effect before drawing the texture with the spritebatch.
m_apfelbeck
m_apfelbeck
Have you measured the performance you get when you're still rendering the scene in the background? To me it seems like an unnecessary complication to render to texture and then save it off unless your getting a hit to your frame rate.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.