Hi
I have a renderTarget texture which I would like to set transparent, draw some stuff offscreen then I copy a part of the renderTarget texture to the main screen.
My code looks like this:
GraphicsDevice.SetRenderTarget(_board2D);
GraphicsDevice.Clear(Color.Transparent);
SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointWrap, null, null, null, null);
_board.Draw(SpriteBatch);
SpriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.Yellow);
SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.Opaque, null, null, null, null, _screenMatrix);
SpriteBatch.Draw(_textures[_TEXTURE_BACKGROUND], Vector2.Zero, null, Color.White, 0f, Vector2.One, 1, SpriteEffects.None, 0.6f);
SpriteBatch.Draw(_board2D,
_boardBoundsView.Location.ToVector2(),
new Rectangle((int)_board.ViewPortOffset.X, (int)_board.ViewPortOffset.Y, _boardBoundsView.Width, _boardBoundsView.Height),
Color.White,
0,
Vector2.Zero,
Vector2.One,
SpriteEffects.None,
_DEPTH_BOARD);
The result is a black background. If I change the second line to:
GraphicsDevice.Clear(Color.Red);
Then the background becomes red. So a solid colour is OK but a transparent colour is not.
I looked around online and found these:
http://stackoverflow.com/questions/9928868/c-sharp-xna-rendertarget2d-clearcolor-transparent-not-working
http://stackoverflow.com/questions/16350500/rendertarget2d-not-preserving-transparent-background
Which looks like the same as my code
I’m not sure what I am doing wrong?
I’m using Monogame.Framework.WindowsUniversal v3.6.0.1625 on Windows 10.