Page 1 of 1

OpenGL variable image transparency

Posted: Wed Sep 14, 2005 8:46 pm
by Guest
This line demonstrates the problem:

Code: Select all

itsDriver->draw2DImage(itsImage, pos, itsSourceRect, 0, video::SColor(alpha,255,255,255), true);
The image is either not drawn at all (alpha of 0) or with the full opacity from the texture (alpha 1-255).

After playing around with the engine source a bit, and searching through the net I found the original code from zola, and saw a difference in the "setRenderStates2DMode"-function.

zola's original code (only the relevant part):

Code: Select all

if (alphaChannel)
{
   glEnable(GL_BLEND);
   glDisable(GL_ALPHA_TEST);
   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,  GL_MODULATE);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
}
...and the code currently in Irrlicht:

Code: Select all

if (alphaChannel)
{
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);

   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glEnable(GL_BLEND);

   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
}
I don't know much about OpenGL so I can't tell what the new code was supposed to fix, but I replaced it with the old one, and lo and behold, the alpha issue is gone.
Makes a pretty good workaround obsolete that I already wrote...

Could someone with OpenGL experience please look this through? I doubt that the code was changed without reason, so I fear I may be trading one evil for another.

MedO

Re: OpenGL variable image transparency

Posted: Wed Sep 21, 2005 8:14 am
by Andi|xng
I have the same problem! draw2DImage does not work with transparency in OpenGL! ColorKeys work, but not 8 bit alpha from the SColor argument.

Please fix this bug soon! The solution seems really to be easy, so it should not be much work.

Posted: Thu Sep 22, 2005 7:45 am
by Guest
You are using the correct Alpha flags ("add_color" not the boolean one)?

I'm sure I had a semi transparent multicoloured quad up and running that worked fine in both DX and OGL. Check your flags, though I may be wrong as I haven't touched OGL for a while.

Posted: Thu Sep 22, 2005 8:28 am
by Andi|xng
I did not know that there are flags that change the behavior of draw2DImage :shock: Can you give me a code example?

Posted: Fri Sep 23, 2005 6:15 pm
by jirr
Anonymous wrote:You are using the correct Alpha flags ("add_color" not the boolean one)?

I'm sure I had a semi transparent multicoloured quad up and running that worked fine in both DX and OGL. Check your flags, though I may be wrong as I haven't touched OGL for a while.
As I do think this applies to Materials only not to draw2DImage.
Would be glad if someone could prove the opposite.

So the question is: does any possibility or workaround exist to use alpha in connection with draw2DImage on a full image (i.e. ALL colors <=> ALL pixels of the texture) or is there a bug as suspected by three persons already?

Posted: Fri Sep 23, 2005 7:25 pm
by Guest
Well, I posted my workaround right on top... :-)
I didn't see any problems with it yet, but there HAS to be some reason why the code was originally changed.
And I don't see any connection to material flags, not in the documentation nor in the sourcecode (though I didn't look too hard).

MedO

Posted: Sat Jul 08, 2006 6:53 am
by pok
I had same problem in irrlicht 1.0 and then changed source like MedO, it works perfectly.

I guess why it it changed :
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=3269