CHAPTER 5: Textures (^153)
Naturally, drawInRect() also needs some changes. Swap out your old drawInRect() for
the new and improved version in Listing 5-5. This will cause the z value to oscillate back
and forth.
Listing 5-5. Subsitute this for your drawInRect.
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
static int counter=1;
static float direction=-1.0;
static float transZ=-1.0;
static GLfloat rotation=0;
static bool initialized=NO;
static const GLfloat squareVertices[] =
{
-0.5f, -0.5f,-0.5f,
0.5f, -0.5f,-0.5f,
-0.5f, 0.5f,-0.5f,
0.5f, 0.5f,-0.5f
};
static GLfloat textureCoords[] =
{
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
1.0, 1.0
};
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f,0.0f,transZ);
glRotatef(rotation,0.0,0.0,1.0);
glVertexPointer(3, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glTexCoordPointer(2, GL_FLOAT,0,textureCoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);