Pro OpenGL ES for iOS

(singke) #1

CHAPTER 4: Turning On the Lights (^103)
same normal, you can dump the normal array and use glNormal3f() instead, saving a
little memory and CPU overhead in the process.
Let’s make one final tweak. For this example, ensure that the planet is allocated with the
stack and slice values set back to 10 each This makes it easier to see how some of the
lighting works. Now you can compile and run it for real, and if you get something similar
to Figure 4-5, relax and take a pause for a cool refreshing beverage.
Figure 4-5. Flat lighting
Now that you’re back, I am sure you’ve spotted something a little odd. Supposedly the
geometry is based on strips of triangles, so why are the faces those weird four-sided
triangle things?
When set for flat shading, OpenGL picks up its illumination cue from only a single vertex,
the last one of the respective triangle. Now, instead of the strips being drawn from
triangles in horizontal pairs, think of them loosely coupled in vertical pairs, as you see in
Figure 4-6.

Free download pdf