How do you make the background of a texture transparent when it overlaps?

601 Views Asked by At

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 texture, the black background still shows. How do I make my texture transparent, even when it overlaps?

1

There are 1 best solutions below

3
On

I'm assuming 3 things here

  1. You're succesfully loading an image with an alpha channel (like a .png or .tga)
  2. You've got depth testing enabled
  3. 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.