OpenGL variable image transparency

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Guest

OpenGL variable image transparency

Post 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
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Re: OpenGL variable image transparency

Post 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.
Guest

Post 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.
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Post 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?
jirr
Posts: 36
Joined: Sat Feb 19, 2005 8:05 am

Post 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?
Guest

Post 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
pok
Posts: 2
Joined: Wed Jul 05, 2006 4:24 pm

Post 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
Post Reply