RenderTarget2D behavior in XNA

Posted by Utkarsh Sinha on Game Development See other posts from Game Development or by Utkarsh Sinha
Published on 2012-04-02T03:03:00Z Indexed on 2012/04/02 5:43 UTC
Read the original article Hit count: 410

Filed under:
|

I've been dabbling with XNA for a couple of days now. This chunk of code doesn't work as I expect. The goal is to render sprites individually and composite them on another rendertarget.

P = RenderTarget2D(with RenderTargetUsage.PreserveContents)
D = RenderTarget2D(with RenderTargetUsage.DiscardContents)

for all sprites:
    graphicsDevice.SetRenderTarget(D);
    <draw sprite i>

    graphicsDevice.SetRenderTarget(P);
    <Draw D>

graphicsDevice.SetRenderTarget(null);
<Draw P>

The result I get is - only the last sprite is visible. I'm sure I'm missing some piece of information about RenderTarget2D. Any hints on what that might be?

Cross posted from - http://stackoverflow.com/questions/9970349/weird-rendertarget2d-behaviour

© Game Development or respective owner

Related posts about XNA

Related posts about xna-4.0