Question

I'm having some troubles rendering a texture that has a 8 bit alpha channel - namely, its being flattened to 1 bit and glBlendFunc() doesn't seem to be doing anything.

Here is the immediate mode call:

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


glBegin(GL_QUADS);
{

    glTexCoord2f(0, 0);
    glVertex2f(0, 0);

    glTexCoord2f(1, 0);
    glVertex2f(356, 0);

    glTexCoord2f(1, 1);
    glVertex2f(356, 356);

    glTexCoord2f(0, 1);
    glVertex2f(0, 356);

}

glEnd();

Needless to say, there are a variety of OpenGL states that have been set behind the scene, and clearly one of them

Are there any states I'm not aware of that can interfere with the blending stage?

Have I got the blendfunc right? That seems to be correct from the internet pages I looked on - I have however checked the texture in GDEBugger so the image has definitely been loaded with an 8 bit alpha channel, as well as trying out images with no alpha channel and with a one bit alpha channel.

Any help would be greatly appreciated!


Edit:

In response to answers: I'm using the SOIL image loading library, I'm gonna take a look through its source and see how it does things. Right now, I'm just rendering this image on top of an already rendered scene - its definitely not facing depth issues - in fact the depth buffer test is off.

Was it helpful?

Solution

Transparency is best implemented using blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest to nearest.

I would check to make sure your polygons are sorted back to front, otherwise blending will have incorrect effects.

I would also make sure your call to glTexImage2D is using GL_RGBA or GL_BGRA when loading the texture.

EDIT:

Also, glEnable(GL_ALPHA_TEST) and remember to set your alpha function using glAlphaFunc.

http://www.gamedev.net/topic/105082-glalphafunc/

OTHER TIPS

You didn't post another important part, that is how did you create and configure your texture. And I think the problem lies there, not in the code you posted.

In order to make the blending to work in the above case, you have to have alpha channel enabled in the texture.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top