Pro OpenGL ES for iOS

(singke) #1

CHAPTER 4: Turning On the Lights (^107)
Figure 4-8. Without green material defined (left) and with it defined (right)
Let’s do one more experiment. Let’s make the diffuse light be a more traditional white.
What should now happen with the green? Red? How about blue? Since the white light
has all those components, the colored materials should all show up equally well. But if
you see the black ball again, you changed the material’s color, not the lighting.
Specular Lighting
Well, how about the specular stuff? Add the following line to the lights section:
glLightfv(SS_SUNLIGHT,GL_SPECULAR,red);
To the material section, add this:
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, red);
And change the light’s position to the following:
GLfloat pos[]={10.0,3.0,0.0,1.0};

Free download pdf