A language that doesn't affect the way you think about programming is not worth knowing Concept 2 : A Hidden-Surface Removal ==================================== Idea: ===== When we render a scene composed of three dimensional objects, some of them might obscure all or parts of others. Changing the viewing point can also change the obscuring relationship. The elimination of parts of solid objects that are obscured by others is called hidden-surface removal. The Depth Buffer (or Z Buffer): =============================== The depth buffer works by associating a depth or distance, from the view plane (remember the near clipping plane of glFrustum() and glOrtho()) with each pixel on the window. Before each pixel is drawn a comparision is done with the existing depth value. If the value is greater than the currently stored value, the new pixel is not rendered. If the converse is true, the new pixel is drawn. Experiment: =========== The sphere rendering commands are followed by the cube rendering commands in our example. The sphere is rendered 3 units in front of the cube. Hence with depth buffering enabled the sphere obscures part of the cube. With depth buffering disabled, the cube even though it is located behind the sphere in our scene, gets rendered completely and obscures the sphere in front of it. glutInitDisplayMode(GLUT_DEPTH | ....); initializes the depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Clears the depth buffer initially in the program glEnable(GL_DEPTH_TEST); Enables depth testing of pixels before rendering