PDA

View Full Version : Applying a texture on a transparent polygon



rookie
04-05-2011, 12:08 PM
Hey guys, basically my problem is that i need to apply a .PNG texture (with some transparent parts) to a polygon, but i need the polygon to be transparent in the parts where the .PNG is transparent. Problem is, i either apply the texture and both the texture and polygon are solid or both are transparent. Here is the code and thanks for any reply.


glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glAlphaFunc(GL_GREATER,0.0f);


glBindTexture(GL_TEXTURE_2D, hud_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ALPHA);

glColor4f(1.0f,1.0f,1.0f,0.0f);

glBegin(GL_QUADS);
glTexCoord2d(0.0,1.0); glVertex3f(0,0,0);
glTexCoord2d(1.0,1.0); glVertex3f(512,0,0);
glTexCoord2d(1.0,0.0); glVertex3f(512,256,0);
glTexCoord2d(0.0,0.0); glVertex3f(0,256,0);
glEnd();

glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);

mhagain
04-05-2011, 12:49 PM
Change this:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ALPHA);To this:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);And remove your glColor4f.

Also worth noting that glTexParameter functions only need to be used when the texture is originally created (or if you wish to change the tex params).

rookie
04-05-2011, 04:18 PM
Change this:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ALPHA);To this:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);And remove your glColor4f.

Also worth noting that glTexParameter functions only need to be used when the texture is originally created (or if you wish to change the tex params).

works perfectly now, thanks alot ;)