SphereWorld with Fog

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);

SphereWorld with Fog
SphereWorld without Fog

Note how the fog darkens the green spheres that are farther back in the scene, and that the shadows get less distinct.

Advertisements
This entry was posted in OpenGL. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s