OpenGL Depth Buffering Functions

Space must be allocated for the depth buffer when a window is initialized:

glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

The depth buffer must be cleared each time the scene is drawn:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

The depth buffering test must be enabled:

glEnable(GL_DEPTH_TEST);