TUTORIAL 1 - OpenGL Fundamentals

1  2  3  4  5  6  7  8  9  10  11  12  13

Lighting and Materials

The light we see all around us actually consists of a couple of different components:

ambient light: this light scattered so often, that it comes from no particular direction but is uniformly distributed in the environment. If you specify no lighting in OpenGL, the result is the same as if you define only ambient light.

diffuse light: this light comes from a certain direction but is reflected homogenously from each point of the surface. Examples for diffuse light are all area lights like fluorescent lights for example.

specular light: specular lights are the highlights, that can be seen on the surface of shinny materials.

Although the diffuse and ambient light is independent of the material, the specular light depends strongly on the material and especially on it's shininess. For example rubber has a very low shininess, while plastic and ceramics have a high shininess. In OpenGL we can specify the parameters of the light source with the command

void glLightfv(GLenum Light, GLenum ParameterName, const GLfloat *ParameterValue)

Depending on the variable type you want to use for the ParameterValue, you can alternatively use glLighti (..., …, GLint), glLightf (…, …, GLfloat) or glLightiv (…, …, const GLint). The first parameter of this function is a symbolic name, that identifies the light and is of the form GL_LIGHT0, GL_LIGHT1,… GL_LIGHT7. In some OpenGL implementations you can have more than eight lights, but it is always a good idea to stay on the safe side. Now that we know all the lighting parameters we have to take a look at the materials, since they can have a significant influence on the lighting. The material of an object determines how much of the different light components is reflected, its shininess and even whether the material itself emits light. To set these parameters, we can use the command

void glMaterialfv(GLenum face, GLenum ParameterName, const GLfloat *ParameterValue)

The face parameter specifies to which side of the polygon the material will be applied. Allowed values are GL_FRONT, GL_BACK and GL_FRONT_AND_BACK. Like before the second parameter is the most interesting one and determines the actual material.

previous   next