graphics - Transparency issue loading texture from PNG in Monogame -


i'm trying accomplish figure should quite simple in monogame gl on windows.. load texture png file , render screen sprite. far i'm having lot of trouble this. i'm loading png texture2d following code (f#):

    use file = system.io.file.openread("testtexture.png")     this.texture <- texture2d.fromstream(this.graphicsdevice, file) 

and rendering with:

    this.spritebatch.begin(spritesortmode.immediate, blendstate.nonpremultiplied);     this.spritebatch.draw(this.texture, vector2.zero, color.white)     this.spritebatch.end() 

the problem kind of weird effect alpha channels, if there's channels not being alpha pre-multiplied or something, can't place sure what's happening. what's notable though exact same code renders using official xna libraries. issue in monogame, tested version 3.0 , 3.2, both of have same issue.

here's rendering test png in monogame illustrate problem:

http://i.imgur.com/dny26gi.png

the background in each image cornflower blue, pure red, green , blue respectively. notice in image red background, can see dark outline around red lines in texture. outline shouldn't there lines , background both pure red. note same thing occurs around blue lines in image blue background, not in image green background. in image green lines blend in green background should.

below how exact same file renders using official xna library.

http://i.imgur.com/2rtqhuk.png

notice how blue, green , red lines blend in background when background same colour. correct behaviour.

given same code behaves differently in both xna , monogame, believe there must bug in framework. have guess bug might , of nature? if it's easy fix best solution might fix bug myself.

besides though want learn way can load png , render correctly screen in monogame. i'm sure can't first 1 who's wanted this. avoid content pipeline if @ possible, sake of simplicity.

update

i've done more digging trying figure out nature of problem. i've changed testtexture.png file more revealing alpha blending problems. after using new texture file, took screenshots of incorrect monogame rendering , viewed in it's separate colour channels. what's happening pretty perplexing me. though might simple case of blendstate.nonpremultiplied being ignored, i'm seeing looks more complicated that. among other things, green colour channel appears blending differently blue , red channels. here's rather large png image that's compilation of screenshots , explanations i'm talking about:

i.imgur.com/ceuqqm0.png

clearly there's kind of bug in monogame windows gl, , possibly other editions haven't tried (though i'd interested see verified). if thinks know might happening here please let me know.

lastly, here's project files reproduce problem i'm having:

mega.co.nz/#!llfxbbrb!orppin4tu2uahhuospl03nqotajfk59cfxi5tdzlyyi

this issue has been resolved. bug in framework found at: monogame.framework/graphics/imageex.cs in following method:

internal static void rgbtobgr(this image bmp) {     system.drawing.imaging.imageattributes ia = new system.drawing.imaging.imageattributes();     system.drawing.imaging.colormatrix cm = new system.drawing.imaging.colormatrix(rgbtobgr);      ia.setcolormatrix(cm);     using (system.drawing.graphics g = system.drawing.graphics.fromimage(bmp))     {         g.drawimage(bmp, new system.drawing.rectangle(0, 0, bmp.width, bmp.height), 0, 0, bmp.width, bmp.height, system.drawing.graphicsunit.pixel, ia);     } } 

changing fixes issue:

internal static void rgbtobgr(this image bmp) {     using (bitmap bmpcopy = (bitmap)bmp.clone())     {         system.drawing.imaging.imageattributes ia = new system.drawing.imaging.imageattributes();         system.drawing.imaging.colormatrix cm = new system.drawing.imaging.colormatrix(rgbtobgr);          ia.setcolormatrix(cm);         using (system.drawing.graphics g = system.drawing.graphics.fromimage(bmp))         {             g.clear(color.transparent);             g.drawimage(bmpcopy, new system.drawing.rectangle(0, 0, bmp.width, bmp.height), 0, 0, bmp.width, bmp.height, system.drawing.graphicsunit.pixel, ia);         }     } } 

what's happening when rgbtobgr conversion performed, draws converted version of image on top of image object it's converting from. what's causing strange effects. far can tell thing clear image object before drawing on again, of course means bitmap being converting must copied can read copied version while writing on original version cleared.

thanks dellis1972 pointing me in right direction on this: https://github.com/mono/monogame/issues/1946


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -