Pro OpenGL ES for iOS

(singke) #1

106 CHAPTER 4: Turning On the Lights^


GLfloat halfcyan[]={0.0,.5,.5,1.0};

//Lights go here.

glLightfv(SS_SUNLIGHT,GL_POSITION,pos);
glLightfv(SS_SUNLIGHT,GL_DIFFUSE,green);

//Materials go here.

glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red); // 1

glShadeModel(GL_SMOOTH);

glEnable(GL_LIGHTING);
glEnable(SS_SUNLIGHT);

glLoadIdentity();
}
If you see our old friend, the supermassive black hole from M31, you’ve done well. So,
why is it black? That’s simple; remember the discussion at the start of this chapter on
colors and reflectance? A red object looks red only when the lighting hitting it has a red
component, precisely the way our green light doesn’t. If you had a red balloon in a dark
room and illuminated it with green light on it, it would look black, because no green
would come back to you. And if someone asks you what you’re doing with a red balloon
in a dark room, just growl ‘‘Physics!’’ Then tell them that they just wouldn’t understand in
a dismissive tone.
So, with this understanding, replace the red diffuse material with green in line 1. What
should you get? Right, the green sphere is illuminated again. But you may notice
something really interesting. The green now looks a little bit brighter than before adding
the material. Figure 4-8 (left) shows it without any material specified, and Figure 4-8
(right) shows it with the green diffuse material added.
Free download pdf