HomeMultimedia Page 3 - Basic Lighting in OpenGL and SDL Game Programming
Lighting Model - Multimedia
Lighting is one of the components of a game that can provide an immersive reality to the player -- or be so distracting that playing becomes difficult. To ease working with lighting, OpenGL provides simplified API. The focus of this discussion will be on the basics of using lighting API provided by OpenGL. This article is the latest part in a multi-part series on game programming with OpenGL and SDL.
The final step is to choose a lighting model. The lighting model determines two things. First, it determines whether the user is viewing the scene from an infinite distance or locally. If the user is considered to be viewing from an infinite distance, the angle of light and that of the viewer is ignored. The result will be unrealistic lighting. Secondly, the lighting model determines whether or not the front and back surface calculations for an object need to be done separately.
To choose a lighting model, the glLightModel*() method is used. This method, or command as it is known in OpenGL, is used to set the amount of global ambient light that will be cast on the objects on the scene.
One of the variants of glLightModel*() is glLightModelfv(). It takes a parameter telling OpenGL that global ambient light needs to be set, and the array defining the color of global ambient light. For example, to set the global ambient light with the color having values of 0.5f, 0.5f, 0.5f and 1.0f, the statements will be:
That completes the steps necessary for implementing basic lighting in an application or game. In the next section, basic lighting will be added to the existing framework.