Hello, I’m new here and hopefully I’m not posting this in the wrong place.
I have been working on a ‘small’ pet project that started in the days of XNA 3. I put it on Ice when MS killed XNA and finally I was able to get it working again with MonoGame. It started out as a web application, a browser game if you like and slowly evolved into a client program, based on XNA, that connects to the server over web services. A homebrew 3D engine renders and animates scenes in the background and a (also homebrew) UI provides the actual gameplay. Sure beats motionless webpages. Here is a recent screenshot:
The UI inherited a problem from its XNA 3 origins: Rendering spritefonts was changed from nonpremultiplied to premultiplied. The settings remained the same when I ported everything to XNA 4, so rendering text still worked well without changes.
Now, with MonoGame, I can’t set the spritefonts to be prepared nonpremultiplied anymore. I had to set the BlendState to BlendState.AlphaBlend when drawing the UI, like this:
SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, oState);
With this change the text looked fine again, but a new problem has appeared, which I could not yet fix. The controls of the UI are drawn in two stages. When property changes in a control demand it to be redrawn, the new appearance is rendered into a RenderTarget2D object. then, when a frame is rendered, the rendering thread simply walks through the control tree of the UI and draws the texture from each control, also with a SpriteBatch set to BlendState.AlphaBlend.
Now this is the problem: Controls can have transparent backgrounds. Now, with AlphaBlending, the alpha value of the background color has no effect anymore. It seems locked to a certain degree of transparency, no matter what value the alpha value of the background color actually has.
The background of the RenderTarget2D objects is set by the following line. When drawing nonpremultiplied, this worked perfectly.
GraphicsDevice.Clear(ClearColor);
As I see it, clearing the RenderTarget2D with the color does not work. I must use a value that makes the texture in the RenderTarget2D a premultiplied texture, but I’m not sure how to do that.