Game Development Reference
In-Depth Information
Portability
Because most organizations have invested significant resources in PC development
(including OpenGL and others), it makes no business sense to start from scratch to enter the
mobile gaming arena. With a few tricks and tips, your engine PC code can work efficiently in
mobile processors. In this section you'll learn these tricks and tips, plus some of the caveats
about reusing graphics code in multiple platforms, including the following:
Immediate mode : This is a technique commonly used in OpenGL on the
PC and Mac to render geometry in 3D space. The problem in mobile is
that it has been removed for efficiency's sake. If you are reusing graphics
code from the PC, it will probably be full of immediate mode calls.
Other less critical issues : Such as loading textures (which is slightly
different in GL ES), display lists, handling attribute state, and others.
But first let's look at the issues surrounding immediate mode.
Handling Immediate Mode
Take a look at the following code fragment that renders a square in the XY plane (shown in
Figure 4-1 ):
glBegin( GL_QUADS ); /* Begin issuing a polygon */
glColor3f( 0, 1, 0 ); /* Set the current color to green */
glVertex3f( -1, -1, 0 ); /* Issue a vertex */
glVertex3f( -1, 1, 0 ); /* Issue a vertex */
glVertex3f( 1, 1, 0 ); /* Issue a vertex */
glVertex3f( 1, -1, 0 ); /* Issue a vertex */
glEnd(); /* Finish issuing the polygon
The code above is asking to draw 4 vertices (a rectangle or quad) and to fill this geometry
with a green color. This code is typical in OpenGL but it will not compile in GL ES.
Nevertheless it can be easily rendered in GL ES using arrays and glDrawArrays (which by the
way are supported by both GL and GL ES), as you can see in the next fragment:
GLfloat q3[] = {
-1, -1,0,
-1, 1, 0,
1, 1, 0,
1, -1,0
}; /* array of vertices */
glEnableClientState(GL_VERTEX_ARRAY); /* enable vertex arrays */
glColor3f( 0, 1, 0 ); /* Set the current color to green */
glVertexPointer(2, GL_FLOAT, 0, q3);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glDisableClientState(GL_VERTEX_ARRAY);
 
Search WWH ::




Custom Search