mono/MonoGame — Issue #346: RenderTarget - Only last call to spritebatch is drawn
Author: degborta
Created: 2012-03-02 08:15:03+00:00
State: open

When setting RenderTarget and using more than one spriteBatch.Begin() and spriteBatch.End() call during Draw() only the last call is drawn to the RenderTarget.

This seems to happen on iOS but not on Windows, those are the only platforms I have tested.

protected override void Draw (GameTime gameTime)
{

GraphicsDevice.Clear (Color.CornflowerBlue);

Rectangle bound1 = new Rectangle (0, 0, width, height);
Rectangle bound2 = new Rectangle (5, 5, width, height);

GraphicsDevice.SetRenderTarget (render);
GraphicsDevice.Clear (Color.CornflowerBlue);

spriteBatch.Begin ();
spriteBatch.Draw (debug, bound1, Color.White);
spriteBatch.End ();

spriteBatch.Begin (SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Matrix.Identity);
spriteBatch.Draw (debug, bound2, new Color (1, 0, 0, 0.5f));
spriteBatch.End ();

GraphicsDevice.SetRenderTarget (null);
GraphicsDevice.Clear (Color.CornflowerBlue);
Texture2D final = (Texture2D)render;

spriteBatch.Begin ();
spriteBatch.Draw (final, bound1, Color.White);
spriteBatch.End ();

base.Draw (gameTime);
}