RenderTarget2D GraphicsDevice.Clear(Color.Transparent) not working

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.

what’s the format of your rendertarget (how did you intitialize it)

EDIT: It seems to work for a straight windows project. I have no idea why but I can’t create a default UWP project, some macro is broken for me. Anyways, here’s the link to the project, see if it works for you.

So it may be a problem with UWP in particular?

I’m using:

_board2D = new RenderTarget2D(GraphicsDevice,
1000,
1000);

I had a look at your code and it is the same way you’re initializing it. I even ran your code and it does draw a transparent texture. I’ll do some more testing and try and determine if it is UWP problem.

I didn’t use the Monogame UWP template to create the project. I think I use NuGET to install Monogame into the project.

Thanks

Changed BlendState.Opaque to BlendState.AlphaBlend then it worked