Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am working on a cool little city generator which makes cities in the isometric perspective. However, a problem arose where if the grid size was over a certain limit it would have awful lag. I found the main problem to be in the draw method. So I took the precautionary step of rendering only items that were onscreen. This fixed the lag but, not by much.

The idea I have is to render the frame once and take a snapshot. Then, display that as a texture2d on screen. This way I don't have to render 1,000,000 objects every frame since they don't change anyways.

TL;DR - I want to

  1. Take a snapshot of an already rendered frame
  2. Turn it into a Texture2D
  3. Render that to the screen instead of all the objects.

Any help appreciated.

share|improve this question
add comment

2 Answers

Another method would be using RenderTargets which would basically consist of these steps

  1. Create a render target A
  2. Set A on the device
  3. Render everything you want
  4. Unset A
  5. You can now use A as a texture (render targets inherit from Texture2D).

The advantage of this is that it works on the Xbox 360 and Windows Phone as well (the screenshot approach by Marton doesn't).

You can find a small tutorial I found that explains the steps more in detail here

share|improve this answer
    
Can it render everything that is off screen as well? –  redcodefinal Nov 11 '12 at 21:07
    
You can use a render target off screen if you mean that :). –  Roy T. Nov 12 '12 at 8:45
add comment
  1. Take a snapshot with the GraphicsDevice.GetBackBufferData method.

  2. Load the resulting data into a Texture2D with the Texture2D.SetData method.

  3. Render the Texture2D.

Example: Taking a screenshot using XNA 4.0

share|improve this answer
    
This was helpful for other things but not what I was looking for. I needed a way to render the entire city, even the stuff that was off screen. This only takes the pixels on screen and puts them into a texture2d. :( –  redcodefinal Nov 11 '12 at 8:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.