Pro OpenGL ES for iOS

(singke) #1

CHAPTER 4: Turning On the Lights (^105)
Figure 4-7. From left to right, smooth shading a sphere with 20 stacks and 20 slices, flat shading on a sphere of
only 5 stacks and slices, followed by smooth shading
Fun with Light and Materials
Now, since we have a nice smooth sphere to play with, we can start tinkering with the
other lighting models and materials. But first a thought experiment: say you have a
green sphere as shown earlier but your diffuse light is red. What color will the sphere
be? (Pause for the Jeopardy theme.) Ready? Well, in the real world what would it be?
Reddish green? Greenish red? A mauvy shade of pinky russet? Let’s try it and find out.
Modify initLighting() again, as shown in Listing 4-4. Note that the light vectors have
been renamed to their specific colors to make it a little more readable.
Listing 4-4. Adding Some More Light Types and Materials
-(void)initLighting
{
GLfloat pos[]={0.0,3.0,0.0,1.0};
GLfloat white[]={1.0,1.0,1.0,1.0};
GLfloat red[]={1.0,0.0,0.0,1.0};
GLfloat green[]={0.0,1.0,0.0,1.0};
GLfloat blue[]={0.0,0.0,1.0,1.0};
GLfloat cyan[]={0.0,1.0,1.0,1.0};
GLfloat yellow[]={1.0,1.0,0.0,1.0};
GLfloat magenta[]={1.0,0.0,1.0,1.0};

Free download pdf