Loading texture form PNG in Monogame transaprency issue
I'm trying to accomplish something that I figure should be quite simple in
MonoGame GL on Windows.. That is to load a texture from a PNG file and
render it to the screen as a sprite. So far I'm having a lot of trouble
with this. I'm loading the PNG to a Texture2D with the following code
(F#):
use file = System.IO.File.OpenRead("testTexture.png")
this.texture <- Texture2D.FromStream(this.GraphicsDevice, file)
and then rendering with:
this.spriteBatch.Begin(SpriteSortMode.Immediate,
BlendState.NonPremultiplied);
this.spriteBatch.Draw(this.texture, Vector2.Zero, Color.White)
this.spriteBatch.End()
The problem is some kind of weird effect with the alpha channels, as if
there's something up with channels not being alpha pre-multiplied or
something, but I can't place for sure exactly what's happening. What's
notable though is that the exact same code renders perfectly using the
official XNA libraries. The issue is only in MonoGame, which I tested with
version 3.0 and 3.2, both of which have the same issue.
Here's the rendering a test PNG in MonoGame to illustrate the problem:
http://i.imgur.com/Dny26gI.png
The background in each image is cornflower blue, then pure red, green and
blue respectively. Notice in the image with the red background, you can
see a dark outline around the red lines in the texture. This outline
shouldn't be there as the lines and the background are both pure red. Note
the same thing occurs around the blue lines in the image with the blue
background, but not in the image with the green background. In that image
the green lines blend in with the green background as they should.
Below is how the exact same file renders using the official XNA library.
http://i.imgur.com/2Rtqhuk.png
Notice how the blue, green and red lines blend in to the background when
the background is the same colour. This is the correct behaviour.
Given that the same code behaves differently in both XNA and MonoGame, I
believe there must be a bug in the framework. Would anyone have any good
guess as to where the bug might be and of what nature? If it's an easy fix
then the best solution might be to just fix that bug myself.
Besides that though I really just want to learn a way I can simply load a
PNG and render it correctly to the screen in MonoGame. I'm sure I can't be
the first one who's wanted to do this. I would like to avoid the content
pipeline if at all possible, simply for the sake of simplicity.
No comments:
Post a Comment