338 CHAPTER 10: OpenGL ES 2, Shaders, and...^
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
GLfloat gray=0.2;
glClearColor(gray,gray,gray, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self.effect prepareToDraw]; //4
[m_Earth execute:self.effect];
}
In the update() function, you’ll see how we now need to rely on the matrixy functions
from the new math library; there’s no glRotatef() or glTranslatef(), glPushMatrix(),
or glPopMatrix() in this universe.
Lines 1ff specify the projection matrix, what would normally be given
over to glFrustum() in the alternate universe of version 1.
Line 2 and those following create the matrices we need for the
transformations, ultimately assigning the final modelViewMatrix object
to the transform field of the effect’s own GLKEffectPropertyTransform
object. GLKEffectPropertyTransform contains both the Modelview and
normal matrix.
Not only does the ‘‘effect’’ have its own transformation matrix, it can
also have an additional matrix to handle specific components of that
effect. In this case, line 3 highlights this extra matrix. The Modelview
matrix is for the geometry of the effect, just like it is in version 1, but
this new one can be used to transform other things. In this case, it
could be used to rotate the cube map. Setting it to the identity keeps
the cube map static, letting just the earth model rotate.
When ready, call the prepareToDraw() method of the effect’s class,
and it will apply the new settings, after which you may render the
object itself, with the results shown in Figure 10-9.