Alpha Blending and Depth Testing, at the same time (OGL)

Started by
1 comment, last by GameDev.net 24 years, 7 months ago
From what I understand, your polygons do have to be drawn in back to front order in order for blending/transparency to work. If you draw the slightly transparent polygon first, when you draw the one behind OpenGL has no idea that it needs to blend with it. If you have depth testing enabled, that second polygon won't even be drawn, as something in front of it already has been.

So you pretty much just have to sort the polygons before you draw them. No way around it.

Jonathan

Advertisement
I have got my engine working w/ Alpha blending, but when it draws, one poly might have the wrong ordering and will therefore draw at the back when its not meant to or something. I can fix this using glEnable(GL_DEPTH_TEST); but this then stops blending from working properly. The colours still blend w/ the background, but not w/ the other polys. Is there any way to get it to work. I have guessed that it is because I am drawing the semi-transparent poly first, so it blends w/ the background, and when the solid poly is drawn, it doesn't check to make sure the other was alpha 0.5. Would the only way around this be to sort the poly's and draw them in the right order myself?

Thanks

David

Also, if I remember correctly, besides sorting it you also want to do this:

glDepthMask(TRUE)
//Draw solid polygons

glDepthMask(FALSE)
//Draw transparent polygons

Basically your making the depth buffer read only when your drawing the translucent polygons.

This topic is closed to new replies.

Advertisement