RenderTarget help please.

Hi there. I’m trying to use a RenderTarget to draw persistent data on top of a texture.

I’ve setup my RenderTarget and I draw the game background texture to that Target in the Initialise routine. So, the Render now contains the game background.

In the Draw Procedure I’m setting the G.D.SetRenderTarget to the RenderTarget and drawing the additive sprites.
Then I reset the G.D.SetRenderTarget to nothing and draw the Render to the screen buffer along with the rest of the game.

When I start the game I see the background flash on frame one, then blackness. The rest of the game draws ok, but no RenderTarget data.

If I take out the code writing the additive data on each frame the background stays there. I’m guessing this has to be something I’m doing wrong in the SpriteBatch.Begin(, command.

But I’m floundering trying to find the right settings. Can anyone help?

Thanks.

My thought would be to check the parameters you’re using when creating the render target, make sure you’ve set it to preserve the rendered data.

You do this by creating your render target with one of the overloaded functions that includes ‘RenderTargetUsage’ as a parameter and set it as ‘RenderTargetUsage.PreserveContents’.

Perfect answer.

Many thanks. :smile: