0
\$\begingroup\$

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);
\$\endgroup\$
3
\$\begingroup\$

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);
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .