I have a texture that has a black background which I want to make transparent. The problem is that when I draw this texture in front of another object using the textu开发者_如何学Gore, the black background still shows. How do I make my texture transparent, even when it overlaps?
I'm assuming 3 things here
- You're succesfully loading an image with an alpha channel (like a .png or .tga)
- You've got depth testing enabled
- You haven't changed the blending mode, but have enabled blending
When OpenGL is drawing your Quad/Triangle, it is also drawing to the depth buffer, regardless of whether or not that pixel is transparent (or partially transparent). My guess is that you're drawing this transparent shape first, and then the object behind it last. OpenGL wont draw the back object where the depth buffer already says you've drawn something in front of it, so you're really seeing through the first and second object, out into the 'sky'.
so if the transparent object is always in front, draw it last. Otherwise it gets pretty complicated (Google "depth sorting")
I'll try an add more detail to this when I get home.
精彩评论