Pro OpenGL ES for iOS

(singke) #1

CHAPTER 10: OpenGL ES 2, Shaders, and... (^333)
This is just one very simple example of using a shader. When it comes to space themes,
for example, you might generate a hazy atmosphere around a planet or 3D volumetric
textures to simulate galaxies or nebula. If only I had another ten chapters....


More Fun and Games with GLKit

As mentioned previously, the introduction of the GLKit in iOS 5 was largely designed to
make working in OpenGL ES a little easier. The kit supplied new functionality in four
areas, three of which you already have dealt with and are very handy in either version 1
or 2:


„ GLKView and GLKViewController (hiding some of the messiness when
dealing with the drawing surface)
„ Texture management
„ Math libraries (rich and standardized math API)
„ Effects (standard means to encapsulate shader-based effects)

Of the four, the latter two were specifically targeted to make working with OpenGL ES 2
a little easier. It’s the final one, however, that adds a little bit of extra flash that we’re
going to cover now.


GLKEffects


The GLKEffects library was created as a way to manage shader-based effects. At the
time of this writing, GLKit comes with two prebuilt effects classes, and I am sure we’ll
see more. The core to this is the GLKBaseEffects class. GLKBaseEffects incorporates,
and to use Apple’s term ‘‘mimics,’’ much of what OpenGL ES 1 users had to leave
behind when making the jump to 2. This includes the following:


„ The basic lighting model from OpenGL ES 1, but with only three lights
at a time though, vs. 8 or more under version 1.
„ Materials, using the GLKEffectPropertyMaterial class
„ Support for materials and all of their respective qualities
„ Fog
„ Multitexturing

These are the two subclasses:


„ GLKReflectionMap: Turns an object into a shiny toy

„ GLKSkyboxEffect: Creates a 360-degree panorama
Free download pdf