PDA

View Full Version : Question about transparent texture.



tttsuhu
11-02-2000, 11:21 PM
Hi everybody. I meet a question about transparent texture.
I want to draw two trees which use transparent texture in my scene. My code is like this:

.... // Draw all opacity

glEnable(GL_TEXTURE_2D);
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBindTexture(GL_TEXTURE_2D, m_nID-1);

// Draw tree1
glBegin(GL_QUADS);
glColor3f(1.0f, 1.0f, 1.0f);

glTexCoord2f(1.0f,0.0f);
glVertex3f(-1.0f, -1.0f, -2.0f);

glTexCoord2f(0.0f,0.0f);
glVertex3f(1.0f, -1.0f, -2.0f);

glTexCoord2f(0.0f,1.0f);
glVertex3f(1.0f, 3.0f, -2.0f);

glTexCoord2f(1.0f,1.0f);
glVertex3f(-1.0f, 3.0f, -2.0f);
glEnd();

// Draw tree2
glBegin(GL_QUADS);

glTexCoord2f(1.0f,0.0f);
glVertex3f(-1.0f, -1.0f, -10.0f);

glTexCoord2f(0.0f,0.0f);
glVertex3f(1.0f, -1.0f, -10.0f);

glTexCoord2f(0.0f,1.0f);
glVertex3f(1.0f, 3.0f, -10.0f);

glTexCoord2f(1.0f,1.0f);
glVertex3f(-1.0f, 3.0f, -10.0f);
glEnd();


glDisable(GL_TEXTURE_2D);
glDepthMask(GL_TURE);
glDisable(GL_BLEND);

when the viewpoint is (0,0,0) and the direction is -z axis, the tree1 is near the viewpoint. But tree2 is in front of tree1 in the screen because drawing tree1 is before tree2 and depth buffer is not writable. Must I sort the order of the two trees when draw the scene ? If there are lot of trees, sorting will waste long time. Who can tell me a good way to draw transparent texture?

Thanks for u'r help

jc
11-02-2000, 11:49 PM
Try it with glenable(GL_DEPTH_TEST);

It will sort the faces but if gl_blend is enabled, it will use the alpha channel too.

11-03-2000, 12:06 AM
I do the same thing, but you can use bsp trees the data structure to sort your polys (in this case trees) at load time not each frame..... look up bsp tree in this and the advanced forum if you need more info