Sign in to follow this  
afsd42

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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