Game Development Reference
In-Depth Information
Drawing textured quads is the most common technique used in OpenGL ES. Furthermore,
you can wrap Listing 4-1 in a function and reuse it anywhere you need to draw a textured
quad, thereby avoiding the need to repeat Listing 4-1. Thus you have Listing 4-2.
Listing 4-2. Wrapping Textured Quad Drawing Functions
void GL ES_DrawTexturedQuad ( int vertexSize, int texCoordSize
, GLfloat * vtx, GLfloat * texC)
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(vertexSize, GL_FLOAT, 0, vtx);
glTexCoordPointer(texCoordSize, GL_FLOAT, 0, texC);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
GL ES_DrawTexturedQuad can be reused whenever you need a textured quad; thus Listing 4-1
can be rewritten as Listing 4-3.
Listing 4-3. A Simpler Way of Drawing Textured Quads
GLfloat vtx[] = {
0, 0, 0,
0.5, 0, 0,
0.5, 0.5, 0
0, 0.5, 0
};
GLfloat tex[] = {
0,0,
1,0,
1,1,
0,1
};
GL ES_DrawTexturedQuad (3, 2, vtx, tex);
Listing 4-3 saves you some typing if your code draws a lot of textured quads. Next you'll
look at other portability caveats.
Search WWH ::




Custom Search