Pro OpenGL ES for iOS

(singke) #1

262 CHAPTER 8: Putting It All Together^


glTranslatef(scaledX,scaledY,0);

scaledSize=zoomBias*size;

glScalef(scaledSize,scaledSize, 1);

glVertexPointer(3, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);

glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR);
glBindTexture(GL_TEXTURE_2D,name);
glTexCoordPointer(2, GL_FLOAT,0,textureCoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glColor4f(r,g,b,a);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glMatrixMode(GL_PROJECTION);
glPopMatrix();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
}
A few notes are needed for this:
„ What this routine does, as evidenced by its parameter list in line 1, is
to draw a texture to a specific screen-relative position. The name
parameter is merely its OpenGL ES handle. The color values can be
used to tint the image in whatever way you want. Otherwise, most of
the code resembles the original bouncy square demo from the first
chapter, with some exceptions, of course.
„ Lines 2ff turn off the lighting, because we don’t want it to affect our
images at this level. Likewise, face culling is switched off to ensure
that this block is actually rendered just in case another routine
specified the windingness to be different from what we have here. And
to be safe, ensure that the color array client state is disabled.
Free download pdf