0

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?

Brent
  • 101
  • 1
  • 1
  • 3

1 Answers1

1

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.

Tom
  • 1,221
  • 10
  • 21
  • you still didn't arrive home? I need this – Mazyod Jul 31 '11 at 16:54
  • Have you tried drawing the back object before the transparent object? There really isn't much to add. I can do the "Googling" for you: http://www.opengl.org/wiki/Transparency_Sorting – Tom Jul 31 '11 at 23:42
  • hmm.. thanks, it seems not what I am looking for. http://stackoverflow.com/questions/6890956/overlapping-partially-transparent-shapes-in-opengl/6891264#6891264 – Mazyod Aug 01 '11 at 07:33