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.

In the process of trying to resolve a split screen issue, I've been trying to use a RenderTarget2D to draw a portion of my scene to a Texture2D, and then again to another Texture2D, but the end result of both Texture2D's is coming out the same. Can anybody tell me what I'm doing wrong?

Texture2D camera1Render;
Texture2D camera2Render;

                GraphicsDevice.SetRenderTarget(RenderTarget);
                GraphicsDevice.Clear(Color.Transparent);

                map.Draw(mapDisplayDevice, Camera1, new Location(0, 0), false);

                camera1Render = RenderTarget;

                GraphicsDevice.Clear(Color.Transparent);

                map.Draw(mapDisplayDevice, Camera2, new Location(0, 0), false);

                camera2Render = RenderTarget;

                SetRenderTarget(null);
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

RenderTarget2D is a reference type and you seem to be treating it like a value type.

You have 2 references (camera1Render, camera2Render) to a reference type (RenderTarget) so the same object is referenced by all 3 variables, this is why the Texture2Ds are the same. Anyways since RenderTarget is a Texture2D so you can just do the following and simply use the RenderTarget as a Texture2D in a sprite batch or wherever you need.

RenderTarget2D camera1Render;
RenderTarget2D camera2Render;

GraphicsDevice.SetRenderTarget(camera1Render);
GraphicsDevice.Clear(Color.Transparent);
map.Draw(mapDisplayDevice, Camera1, new Location(0, 0), false);
SetRenderTarget(null);

GraphicsDevice.SetRenderTarget(camera2Render);
GraphicsDevice.Clear(Color.Transparent);
map.Draw(mapDisplayDevice, Camera2, new Location(0, 0), false);
SetRenderTarget(null);
share|improve this answer
    
It's so simple! Thank you much! –  TheBroodian Sep 22 '12 at 19:19
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.