Pro OpenGL ES for iOS

(singke) #1

76 CHAPTER 3: Building a 3D World^


Figure 3-14a,b,c. Moving the object away (left) and then zooming in on it (center). The rightmost image has the
default FOV value set to 60 degrees with the cube at only 2 units away.

Face Culling
Let’s go back to the code you might remember from a few pages ago:
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
As mentioned, the first line tells OpenGL to prepare to do face culling, while the second
instructs which face is to be culled. In this case, the triangles facing away from us don’t
need to be rendered.

Note glEnable() is a frequent call and is used to change various states, from eliminating
back faces, as shown earlier, to smoothing points (GL_POINT-SMOOTH), to performing depth
tests (GL_DEPTH_TEST). It can also affect performance if you use it a lot. Best practice is to
minimize use of glEnable() as much as possible.

Now replace GL_BACK with GL_FRONT, and run the program. See Figure 3-15.
Free download pdf