Pro OpenGL ES for iOS

(singke) #1

104 CHAPTER 4: Turning On the Lights^


Figure 4-6. ‘‘Stacked’’ triangle pairs

In Strip 0, Triangle 1 will be drawn using vertices 0, 1, and 2, with vertex 2 used for the
shading. Triangle 2 will use 2, 1, and 3. Lather, rinse, and repeat for the rest of the strip.
Next for Strip 1, Triangle 41 will be drawn with vertices 4, 0, and 5. But Triangle 42 will
use vertices 5, 0, and 2, with the same vertex as Triangle 1 for its shading. That is why
the vertical pairs combine to form a ‘‘bent’’ quadrilateral.
There are few reasons nowadays to use flat shading, so in initLighting(), swap out
GL_FLAT for GL_SMOOTH.
And now you probably know the drill: compile, run, and compare. Then for fun, decrease
the sphere’s resolution from 10 slices and segments down to 5. Go back to flat shading
on this one, and then compare to smooth shading. See Figure 4-7a, b, and c. Figure 4-
7c is particularly interesting because the shading model starts to break down, showing
some artifacting along the face edges. Now reset the sphere’s resolution back up to 20
or 30 to make it nice and smooth for the next section.
Free download pdf