PDA

View Full Version : Transparent



Kronos259
06-06-2003, 09:08 AM
I have created two cubes ,which have two different textures .What i want to do is make the one transparent. My InitGl is as follows

int InitGL(GLvoid)
{
if (!LoadGLTextures())
{
return FALSE;
}



glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glColor4f(1.0f, 1.0f, 1.0f, 0.5);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);


return TRUE;
}


When drawing the first cube (which i want to have transparent) i have the folowing code in my DrawGLScene

glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);

glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
.....
glEnd();

glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);

glEnable(GL_DEPTH_TEST);

then i draw the second cube


Anyone knows what i do wrong?

dorbie
06-06-2003, 02:48 PM
You should draw your transparent cube last to avoid depth buffer problems, and you should make sure than your texture environment is GL_MODULATE to make sure the polygon alpha is multiplied by the texture alpha and not replaced by it.

Your glBlendFunc is also not that good since it will add the cube to the background as a kind of glowing effect dimmed by alpha:

glBlendFunc(GL_SRC_ALPHA,GL_ONE);

Try this instead:

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);


[This message has been edited by dorbie (edited 06-06-2003).]