96 CHAPTER 4: Turning On the Lights^
Note OpenGL ES has a number of utility functions, with glGet*() being one of the most
commonly used. The glGet* calls let you inquire about the states of various parameters, such
as the current modelview matrix to the current line width. The exact call depends on the type
of data requested. Be careful about using these calls too frequently, particularly in production
code, because they are very inefficient.
Let’s go back to the example code from Chapter 3, where you had a squashed red and
blue planet, and make the following changes:
- Ensure that the squash value is 1.0, and the planet is made up of 10
stacks and 10 slices. - In Planet.m, comment out the line blue+=colorIncrment at the end of
the init() method.
What should you see? C’mon, no peeking. Cover up Figure 4-3 and guess. Got it? Now
you can compile and run. Figure 4-3 (left) is what you should see. Now go back to the
initGeometry method and increase the number of slices and stacks to 100 each. That
should yield Figure 4-3 (right). So, by simply changing a few numbers around, we have a
crude lighting and shading scheme. But this is only a fixed lighting scheme that breaks
down the moment you want to start moving things around. That’s when we let OpenGL
do the heavy lifting.
Unfortunately, the process of adding lights is a little more complicated than just calling
something like glMakeAwesomeLightsDude(), as we will see.