PDA

View Full Version : Blending Issue



ldg21
12-14-2010, 12:08 PM
Hello all great board lots of stuff to be learned here! :D

I have been having this issue for a while now and I can't seem to resolve it. I have an object that I am creating partly transparent via the texture. To do this I am masking, applying the texture I want to be seen, and a texture that has black where I want the texture solid and white where I want it transparent. It works great when there is no light enabled, but fails when light is. Well... not really the object is 2D and the side I make the normal on works fine when there is light on it, but not the other side.

Maybe a screenshot would help:
http://oi55.tinypic.com/14bjuw.jpg

And my code:


glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glDisable (GL_DEPTH_TEST);

glBlendFunc (GL_DST_COLOR, GL_ZERO);
glBindTexture (GL_TEXTURE_2D, texture[0]);

glBegin (GL_QUADS);
glNormal3f(0,0,1);
glTexCoord2d (0, 0);
glVertex3f (-1, -1, 0);
glTexCoord2d (1, 0);
glVertex3f (1, -1, 0);
glTexCoord2d (1, 1);
glVertex3f (1, 1, 0);
glTexCoord2d (0, 1);
glVertex3f (-1, 1, 0);
glEnd();

glBlendFunc(GL_ONE, GL_ONE);
glBindTexture(GL_TEXTURE_2D, texture[1]);

glBegin (GL_QUADS);
glNormal3f(0,0,1);
glTexCoord2d (0, 0);
glVertex3f (-1, -1, 0);
glTexCoord2d (1, 0);
glVertex3f (1, -1, 0);
glTexCoord2d (1, 1);
glVertex3f (1, 1, 0);
glTexCoord2d (0, 1);
glVertex3f (-1, 1, 0);
glEnd();

glEnable(GL_DEPTH_TEST);


Could someone please help me? Thank you.

mfort
12-14-2010, 01:06 PM
I do not understand your concept of masking. But it seems to be too complicated.
Your two pass code computes Result = Texture0*FrameBufferColor + Texture1; When lighting is enabled, then the colors are of course modified by light.

Why don't you use RGBA texture and the most common blending function glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). Your texture alpha channel should be black for pixels with full transparency and white for fully opaque pixels. The gradient between black and whites defines the level of transparency.