6

I have some quads that have a texture with transparency and some objects behind these quads. However, these don't seem to be shown. I know it's something about GL_BLEND but I can't manage to make the objects behind show.

I've tried with:

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

but still not working. What I basically have is:

// I paint the object
draw_ac3d_file([actualObject getCurrentObject3d]);

// I paint the quad
paintQuadWithAlphaTexture();

1 Answers1

6

There are two common scenarios that create this situation, and it is difficult to tell which one your program is doing, if either at all.

Draw Order

First, make sure you are drawing your objects in the correct order. You must draw from back-to-front or else the models will not be blended properly.

http://www.opengl.org/wiki/Transparency_Sorting

note as Arne Bergene Fossaa pointed out, front-to-back is the proper way to render objects that are not transparent from a performance stand point. Because of this, most renderers first draw all the models that have no transparency front-to-back, and then they go back and render all models that have transparency back-to-front. This is covered in most 3D-graphic texts out there.

back-to-front

enter image description here

front-to-back

enter image description here

image credit to Geoff Leach at RMIT University

Lighting

The second most common issue is improper use of lighting. Normally in this case if you were using the fixed-function pipeline, people would advise you to simply call glDisable(GL_LIGHTING);

Now this should work (if it is the cause at all) but what if you want lighting? Then you would either have to employ custom shaders or set up proper material settings for the models.

A discussion of using the material properties can be found at http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=285889

ssell
  • 6,429
  • 2
  • 34
  • 49
  • Uhm, so yea, I'm probably drawing front-to-back...Thanks. – Marc Guirao Majo Sep 01 '11 at 13:54
  • Glad it worked! I remember this issue getting me in the past and being completely frustrating – ssell Sep 01 '11 at 14:40
  • Just know that front-to-back is the right way performance-wise to do things on everything that is non-transparent. But it will work to first to front-to-back on anything non-transparent and then back-to-front on everything transparent. – Arne Bergene Fossaa Sep 01 '11 at 21:10
  • This is an important fact that I unintentionally left out. I will update the answer with this – ssell Sep 01 '11 at 21:16