Space must be allocated for the depth buffer:
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH)
Depth buffering must be enabled:
glEnable(GL_DEPTH_TEST)
Depth buffer must be cleared each frame:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)