Sdl and OpenGL glAlphaFunc

Hi,
I’m having a problem when texturing a quad with a png with aplha values.

The problem is that the part of the quad with alpha values are
appearing as white instead of no appearing at all.

Here’s some of the code.

------Loading of the png.------
SDL_Surface *tmp = IMG_Load(“img.png”);
SDL_SetAlpha (tmp, SDL_SRCALPHA, 0);
SDL_Surface *surf = SDL_DisplayFormatAlpha(tmp);

//Load the texture
glGenTextures(1, &theTexture);
glBindTexture(GL_TEXTURE_2D, theTexture);

glTexImage2D (GL_TEXTURE_2D, 0, 4, surf->w, surf->h, 0, GL_BGRA_EXT,
GL_UNSIGNED_BYTE, surf->pixels);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glEnable(GL_TEXTURE_2D);

//--------------------------------------------------------
//--------------------------------------------------------
//------------ here’s some code of how I init OpenGL ----------------
glEnable(GL_BLEND);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glEnable(GL_ALPHA_TEST);
glAlphaFunc (GL_GREATER, 0.0f);

//---------- END ----------------------

I believe the mistake must be somewhere over here.

Thanks in advance.

David.

David Roguin <nesdavid gmail.com> writes:

Hi,
I’m having a problem when texturing a quad with a png with aplha values.

The problem is that the part of the quad with alpha values are
appearing as white instead of no appearing at all.

I had the exact same problem. The solution I found was that rather than using
GL_DECAL, you use GL_REPLACE. The decal is puting a decal on the object you
define. So it is drawing the correct parts of the texture. But since it is a
decal, it leaves the rest of the box there to be seen (the white part where the
alpha should be) So rather, you call GL_REPLACE which replaces the object you
drew with the texture, using the alpha values as you would expect. So, call
glTexEnvf like this:

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_REPLACE);

Micah