2
votes

I am going through the NeHe tutorials for OpenGL... I am at lesson 8 (drawing a cube with blending). http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=08

I wanted to experiment and change half of the faces to be opaque so that there is always a semi-transparent face opposite to an opaque one and be able to rotate the cube...

I changed the code a little bit, the entire source is there : http://pastebin.com/uzfSk2wB I changed a few things :

  • enable blending by default and set the blending function to glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  • changed the order of drawing the faces and colors for each face.
    • I set the depth testing
    • I draw all the opaque faces
    • I disable depth test
    • I draw all the transparent faces

Now, it's hard to tell exactly what is going wrong, but it definitely does not look right, I cannot recognize what face is opaque compared to the transparent ones, sometimes some faces do not seem to get drawn when they should...etc...

Seems like calculating what face is in front compared to back would not be trivial (although I am sure possible), I hope there is a way of doing that would not need to do that.

Looking either for what is wrong in my code or whether this is not the right way of doing it in the first place.

1
please show a picture. Also, describe what you find looking wrong.Bahbar
Just by the way - you're learning a very outdated and ineffective version of OpenGL right now. Browse SO for some resources for newer OpenGL versions when you feel like it. Newer versions are more convenient too!Kos

1 Answers

4
votes

If you disable depth testing before drawing the transparent faces, then they will be drawn with no regard for their correct z-ordering. It probably looks like the transparent faces are being drawn atop all the other faces. Leave depth testing on.