The OpenGL function calls for defining a material's ambient and diffuse colors are discussed in the other two tutorials for this chapter. The two tutorials also show the necessary calls to define ambient light and to define positional and directional lights. We consider here specular reflecton and the definition of a spotlight.
We use the following call to set a material's specular color for its front faces.
glMaterialfv(GL_FRONT,
GL_SPECULAR, C);
where C is an array of four float values. A material's shininess property is set with the call
glMaterialf(GL_FRONT, GL_SHININESS, S);where S is a float in the range 0.0 to 128.0.
The OpenGL function calls we use to define a spotlight as LIGHT3 are as follows:
glLightfv(GL_LIGHT3, GL_SPECULAR, C); glLightfv(GL_LIGHT3, GL_POSITION, P); glLightfv(GL_LIGHT3, GL_SPOT_DIRECTION, D); glLightf (GL_LIGHT3, GL_SPOT_CUTOFF, A);where C is an array that gives the color. P and D are given in homogeneous coordinates with the fourth component set to 1.0. In the case of P, the first three values are the xyz coordinates of the light's position while the first three values of D specify the direction in which the light is pointing. A is a float that represents one-half of the light's cone angle and is given as degrees. Also, the range of values for A is [0.0, 90.0].