Adding fog to Sphere World is another fast and easy upgrade. In my version, pressing the space bar toggles the fog effect off and on, making the effect of fog very apparent. Adding fog is simply a matter of adding a few lines to the OpenGL initialization:
// Set up fog parameters glEnable(GL_FOG); // Turn fog on glFogfv(GL_FOG_COLOR, fLowLight); // Set fog color to match background glFogf(GL_FOG_START, 5.0f); // How far away the fog starts glFogf(GL_FOG_END, 30.0f); // How far away the fog stops glFogi(GL_FOG_MODE, GL_LINEAR); // Which fog equation to use
In addition, inside the drawing code, the shadow color needed changing to include the alpha channel:
glColor4f(0.0f, 0.0f, 0.0f, 0.5);
Note how the fog darkens the green spheres that are farther back in the scene, and that the shadows get less distinct.