Game Development Reference
In-Depth Information
Immediate Mode Drawing
Immediate mode drawing is perhaps the biggest caveat for the Android version of Quake.
Immediate mode is a technique used for specifying geometry; for example, consider the
following snippet to render an arbitrary polygon and corresponding texture:
// Bind some texture
glBegin (GL_POLYGON);
glTexCoord2f (...);
glVertex3fv (...);
...
glEnd ();
This code is typical of a desktop application; however, it is not valid in Android (which
implements OpenGL ES). This is because OpenGL ES does not support immediate mode
( glBegin/glEnd ) for simple geometry. Porting this code would require line-by-line changes,
which can consume significant resources (especially for a game such as Quake, which has
approximately 100,000 lines of C source).
In OpenGL ES, geometry must be specified using vertex arrays, so the preceding code
becomes something like the following:
const GLbyte Vertices []= { ...};
const GLbyte TexCoords []= { ...};
...
glEnableClientState (GL_VERTEX_ARRAY);
glEnableClientState (GL_TEXTCOORD_ARRAY);
glVertexPointer (..., GL_BYTE , 0, Vertices);
glTexCoordPointer (..., GL_BYTE , 0, TexCoords);
glDrawArrays (GL_TRIANGLES, 0, ...);
This code achieves a similar result as the previous one by using arrays of vertices and
coordinates to describe the polygon, and then drawing using triangles. Now, the renderer of
Quake is full (and I mean full) of immediate mode calls. Believe me when I say that translating
immediate mode into array pointers is not an option. As a matter of fact, there is a project
called GLES Quake ( http://grammerjack.blogspot.com/2009/10/gles-quake-port-of-quake-
to-android.html ) that did just that. The guy even took the time to convert all the C files into
C++. Oh my, I feel sorry for the poor soul who did this work. It must have been painful.
Floating Point Issues
You must also consider floating-point issues. OpenGL ES defines functions that use fixed-
point values, as many devices do not have a floating-point unit (FPU). Fixed-point math is a
technique to encode floating-point numbers using only integers. OpenGL ES uses 16 bits to
represent the integer part and another 16 bits to represent the fractional part. The following
is an example of using a fixed-point translation function:
glTranslatex (10 << 16, 0, 0, 2 << 16); // glTranslatef (10.0f, 0.0f, 0.0f, 2.0f);
 
Search WWH ::




Custom Search