Silicon Graphics

[Prev] [TOC] [Next]



(-) OpenGL Programming Guide
(-) Chapter 6Lighting
(-) A Simple Example: Rendering a Lit Sphere

Create, Position, and Enable One or More Light Sources

Example 6-1 uses only one, white light source; its location is specified by the glLightfv() call. This example uses the default color for light zero (GL_LIGHT0), which is white; if you had wanted a differently colored light, you'd use glLight*() to indicate this. You can include at least eight different light sources in your scene of various colors; the default color of these other lights is black. (The particular implementation of OpenGL you're using might allow more than eight.) You can also locate the lights wherever you desire - you can position them near the scene, as a desk lamp would be, or an infinite distance away, like the sun. In addition, you can control whether a light produces a narrow, focused beam or a wider beam. Remember that each light source adds significantly to the calculations needed to render the scene, so performance is affected by the number of lights in the scene. See "Creating Light Sources" for more information about how to create lights with the desired characteristics.

After you've defined the characteristics of the lights you want, you have to turn them on with the glEnable() command. You also need to call this command with GL_LIGHTING as a parameter to prepare OpenGL to perform lighting calculations. See "Enabling Lighting" for more information about how to do this.


[Prev] [TOC] [Next]

OpenGL Programming Guide


Maintained by Maintainer: Send e-mail to .htm">name@address.