OpenGL: Texture Masking + Depth Testing = Impossible?

Started by
5 comments, last by Jerec 23 years, 5 months ago
I''ve started working on a simple terrain engine in OpenGL and I would like to add things like trees and bushes to it. I want to add them as 2D textured planes with one color being transparent. I read the NeHe tutorial on Masking and got that to work, the only problem is that you have to turn off Depth Testing to make it look right and I''ve run into problems with trees that are supposed to be behind hills and stuff. Is there another way to do Masking with Depth Testing on? Can it be done with Alpha Masks? - Jerec
JerecCM Software"Oro?"
Advertisement
If you create your tree/bush bitmaps with an alpha channel within them using some program that supports this (Paint Shop Pro I think) then you can render them with the alpha bits transparent, and you should be able to leave depth testing on.

Note: not tested.

-Mezz
If you do it like Mezz suggests, then you can/should also use the "Alpha Test" to prevent the transparent parts of the tree-textures from being written into the Z-buffer.
yes like the other guys have said give the transparent parts of your textures an alpha of 0
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0.0);

or

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

the first is quicker

http://members.xoom.com/myBollux
Does anyone know how to specify a certain color as being transparent using Paint Shop Pro - saving as a targa.
Just loading in a bmp - and saying that any pink 255,0,255 pixels must have have 0 in the alpha layer?
i have used psp for a while but last time i looked (maybe psp3) u couldnt save an alpha channel, what u could do is justa save it 24bit and set aside a colour to be transparent and when u load it in opengl change the alpha to zero for colours that math it eg to make the colour red (255,0,0) transparent go
r = getc(f);
g = getc(f);
b = getc(f);
if (r==255 && g==0 && b==0) a=0;
else a=255;

http://members.xoom.com/myBollux
I''ll give it a try - thanks

This topic is closed to new replies.

Advertisement