13.003 Computational Geometry and Visualization
Hidden surfaces
It may be possible to draw all the polygonal faces in the proper order ("painter's algorithm"). Since this ordering must be relative to the viewpoint, the ordering will have to be recalculated whenever the viewpoint changes.
However, a correct ordering may not exist, e.g. cyclic overlap. Also, it is not possible to correctly order polygons that intersect each other without subdividing them along the line of the intersection.
A better way is to associate a depth value with each pixel in the frame buffer. The memory where these values are stored is called the z-buffer. During scan conversion of a polygon, if the new pixel's depth value is greater than the stored value (in other words, the current polygon is behind the polygon already drawn), then the pixel is not updated.
... /* initialize GLUT for double buffering */ glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH); ...
void displayCB(void) { glEnable(GL_DEPTH_TEST); /* enable the z-buffer */ /* draw the geometry here ... */ glDisable(GL_DEPTH_TEST); /* disable to the z-buffer */ }