problem with blending

i got a tree texture, 24 bit, png format
i got a tree mask texture, 256 colors, from black(0% visible) to white(100% visible)

how can i render the tree as a simple 2d texture with parts totally invisible, and some parts 100% opaque ?

i dont want to use masking, because this reduces the performance -> i have to draw everything 2 times

First, take your 24-bit targa file and insert the 8-bit (256 color) mask file as your alpha channel to create a single 32-bit texture. Enable alpha testing by using glEnable(GL_ALPHA_TEST); and setting the alpha comparision using glAlphaFunc(GL_GREATER, 0);

Dan

how to insert it ?

found another (very simple) solution :
glblend on
glcolor4f 1,1,1,1
glblendfunc src_alpha,one_minus_src_alpha -> complete opaque everywhere exept where the texture is black

Problem with the blending approach, it is one of the last things done in the pipeline. With the alpha test method, you can render the tree before or after you render things behind it (i.e. where it should not be rendered, it doesn’t update the depth or color buffers at those pixels). With the blending approach, you need to render it after you render everything behind it (so you have to depth sort your objects). Not to mention you will create extra traffic for GL to update the depth buffer where the color shouldn’t be updated. The alpha test occurs before the depth test (In case you are planning on using a bunch of trees)

Dan

now everything works fine. no more errors.

[This message has been edited by HamsterofDeath (edited 01-16-2003).]

When using alpha test, you get much better results by using glAlphaFunc(GL_GREATER, 0.5) with an antialiased alpha channel.

-Ilkka