Captain Penny's Law: You can fool all the people some of the time, and some of the people all the time, but you Can't fool MOM Concept 1.6 : 3D Blending Moving Objects- Depth Buffer ====================================================== Idea: ===== In the previous concept we saw the importance of the order in which the objects are rendered. This problems is aggravated in the case of scenes where either the viewpoint or the object/s are moving. Animation: ========== In this example we draw an opaque sphere and a translucent cube. Pressing the 'a' key triggers an animation sequence in which the translucent cube moves through the opaque sphere. Pressing 'r' resets the objects to their original positions Notice how as the cube gets in front of the sphere it still retains its translucency. How did we achieve this ? Solution: ========= The solution is to enable depth buffering but to make the depth buffer read-only while drawing the translucent objects. First draw the sphere with the depth buffer in the normal operational mode. Then make the depth buffer read only and draw the cube. When the cube is drawn its depth values are still compared to the values established by the sphere and blended accordingly. To control if the depth buffer is writable, use glDepthMask(); if GL_FALSE is the arguement, the buffer becomes read-only, whereas GL_TRUE restores the normal, writable operation.