-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading a PNG with alpha and rendering not working correctly on Windows GL #1946
Comments
Thanks for one of the most comprehensive bug reports we have ever had :) On 20 August 2013 20:39, battlebottle notifications@github.com wrote:
|
I wonder if this is messing things up https://github.com/mono/MonoGame/blame/develop/MonoGame.Framework/Graphics/ImageEx.cs On 20 August 2013 22:23, Dean Ellis dellis1972@googlemail.com wrote:
|
Hey Dellis, Thanks for the response. You got it in one! The problem seems to be definitely related to ImageEx.cs and the RGBToBGR(Image bmp) method. When I remove the RGBToBGR call from Text2D.FromStream() it loads the texture from the PNG with Red and Blue channels reversed... but the alpha renders correctly! I'm messing about with it now to see can I figure out what's happening, but this is certainly the source of the misbehaviour. |
Success! I believe I have it all working now.
Should be changed to:
in https://github.com/mono/MonoGame/blame/develop/MonoGame.Framework/Graphics/ImageEx.cs What's happening is when the RGBToBGR conversion performed, it draws the converted version of the image on top of the image object it's converting from. This is what's causing the strange effects. As far as I can tell the only thing to do is to clear the image object before drawing over it again, which of course means the bitmap you're converting from must be copied so you can read from the copied version while writing over the original version that was just cleared. That's probably more explanation than was required.. Can I trust someone to submit this fix? Thanks for the help. Spent all day scratching my head over this one :). |
I'll make sure this gets in, thanks for finding the solution :) On 20 August 2013 23:11, battlebottle notifications@github.com wrote:
|
Glad to have been of some help. MonoGame rocks :) |
Has this somehow been fixed elsewhere, or is it forgotten? Cause I'm not seeing the code, as mentioned in here, in the MonoGame repository yet. |
This issue is still not fixed in Monogame 3.3. I'm attempting to render a transparent .PNG file which is primarily red, and in the running file, the image comes out purple. Checking the repository, the change to fix this issue never made it in. |
@fjeandinot - Can you test with the latest development build of 3.5? We though that #2424 resolved this. |
Hi tom ! Still the same result. Sorry. |
@fjeandinot - Are your textures being processed by the content pipeline or being loaded from PNGs? Can you share a simple test project that exhibits the error? |
The picture is loaded from a png processed by inkscape. Here's my tesing code : ` namespace View
} ` Do you want a zipped version of the project with the png ? |
…erwise the colors bleed.
Fixed #1946 Turns out the Image needs to be cleared first otherwise the colors bleed.
If the developpement build is recreated under the next 24 hour, I'll be glad to test every flavor of monogame with the premultiplied and the non premultiplied png with each option. As the viewer produce a direct result, it could be a cool non-regression test. |
The new build is already up... we update the website on every merge to the develop branch. So if you grab the current version it will have the fix in #4487.
Seems like we could make a simpler test. If the issue is just one of I see we have no unit test for |
@fjeandinot - FYI... @Tzenchor is adding some unit tests for |
Hi ! I'have tested the DesktopGL ans the Windows Here's the result for the non premultiplied alpha png :
Here's the result for the premultiplied alpha png :
Something's probably broken with the GL version, but isn't it strange that the windows version act that way ? I think I'm missing a point about the differents version of monogame... |
DesktopGL uses OpenGL to render. Windows uses DirectX. So very different code and graphics layers to the same hardware. |
…erwise the colors bleed.
…erwise the colors bleed.
…erwise the colors bleed.
…erwise the colors bleed.
…erwise the colors bleed.
…erwise the colors bleed.
…erwise the colors bleed.
…erwise the colors bleed.
…erwise the colors bleed.
…erwise the colors bleed.
…erwise the colors bleed.
…erwise the colors bleed.
…erwise the colors bleed.
Hi ! Since you have fixed this problem, the GL version seems to display "nothing" from a png regadless of the BlendState or the png alpha mode. |
Hi, I keep updating my version of monogame by downloading the daily build but the GL version keep not showing raw png... |
I replicated the problem and created a fix in #4609. |
This issue affect MonoGame on Windows GL but may affect other platforms too. It affects MonoGame 3.0, and also 3.2.
Basically loading a texture with this code (F#):
and rendering with this code:
will reproduce the error. This code works fine and renders fine when using the XNA4 libraries, but has weird alpha blending artefacts when using MonoGame.
Here's some renderings to illustrate the issue. First the correct renderings using the XNA libraries
Now the bad renderings using MonoGame:
I've tried to figure out the nature of the issue, but havne;t gotten very far besides realising that it's not a simple case of
BlendState.NonPremultiplied
being ignored or something similar. For examples, on analysis I've noticed the green colour channel blends differently than the red and blue colour channels among other odd things. I've creates a large image that illustrates the issue I've noticed in what is hopefully a useful way:http://i.imgur.com/CEUQqm0.png
Here's the project files for reproducing the bad rendering (F# project):
http://www.qfpost.com/file/d?g=EhZh52Zjc
I also made a post about this issue on stack overflow which may be worth monitoring:
http://stackoverflow.com/questions/18320633/loading-texture-form-png-in-monogame-transaprency-issue
The text was updated successfully, but these errors were encountered: