PDA

View Full Version : blending (masking)



03-17-2004, 12:42 PM
I draw all the transparent objects after the solid objects and i use glDepthMask function for the transparent objects

I want to draw a realistic tree using 2 quads crossing each other (90 deg) and I am using a mask texture to cut out the tree textures

the treetexture draws perfect but i now see the crossing plane right through the other plane.

Is there a way to solve this problem?

this is a piece of that code:

glColor4f(1.0,1.0,1.0,1.0);

glPushMatrix();
Translation();

glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);

glDepthMask(GL_FALSE);

glBlendFunc(GL_DST_COLOR,GL_ZERO);

glBindTexture(GL_TEXTURE_2D,Mask);
glBegin(GL_QUADS);
glNormal3f(0.0,0.0,1.0);
glTexCoord2f(0,1); glVertex3f(size,-size,0);
glTexCoord2f(0,0); glVertex3f(size,size,0);
glTexCoord2f(1,0); glVertex3f(-size,size,0);
glTexCoord2f(1,1); glVertex3f(-size,-size,0);
glEnd();


glBlendFunc(GL_ONE, GL_ONE);
glBindTexture(GL_TEXTURE_2D,Tex);
glBegin(GL_QUADS);
glNormal3f(0.0,0.0,1.0);
glTexCoord2f(0,1); glVertex3f(size,-size,0);
glTexCoord2f(0,0); glVertex3f(size,size,0);
glTexCoord2f(1,0); glVertex3f(-size,size,0);
glTexCoord2f(1,1); glVertex3f(-size,-size,0);
glEnd();

glBlendFunc(GL_DST_COLOR,GL_ZERO);
glBindTexture(GL_TEXTURE_2D,Mask);
glBegin(GL_QUADS);
glNormal3f(1.0,0.0,0.0);
glTexCoord2f(0,1); glVertex3f(0,-size,-size);
glTexCoord2f(0,0); glVertex3f(0,size,-size);
glTexCoord2f(1,0); glVertex3f(0,size,size);
glTexCoord2f(1,1); glVertex3f(0,-size,size);
glEnd();

glBlendFunc(GL_ONE, GL_ONE);
glBindTexture(GL_TEXTURE_2D,Tex);
glBegin(GL_QUADS);
glNormal3f(1.0,0.0,0.0);
glTexCoord2f(0,1); glVertex3f(0,-size,-size);
glTexCoord2f(0,0); glVertex3f(0,size,-size);
glTexCoord2f(1,0); glVertex3f(0,size,size);
glTexCoord2f(1,1); glVertex3f(0,-size,size);
glEnd();

//unset options

glDepthMask(GL_TRUE);

glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
glEnable(GL_CULL_FACE);


glPopMatrix();

endash
03-17-2004, 02:37 PM
If I understand you correctly, you are having the problem that you arent' depth-sorting your polygons. Of course, if you have intersecting polygons, they can't be depth sorted. So break it into four quads, and draw them from far to near..

03-17-2004, 11:37 PM
ok thx for your reply

So I now have to find a proper depth sorting routine

could someone provide me some links concerning this routine

thx in advance

endash
03-18-2004, 07:12 AM
If the trees don't overlap other trees very often, you may only need to sort within each tree, which should be fairly easy. A full depth sort would mean you'd need to store all of your trees in some structure that would allow you to traverse them, like an octree or quadtree.

I'd try google, though.