Jump to content
  • Advertisement
Sign in to follow this  
afsd42

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

This topic is 3333 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

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