Game Development Reference
In-Depth Information
When it comes to advanced OpenGL games written for embedded devices, there are some caveats
that you should be aware of before starting you porting work, which we'll look at in the next section.
Caveats of Porting OpenGL Games to Android
Today's smart phones have become pretty powerful. They feature a GPU capable of advanced graphics.
Nevertheless, when it comes to writing advanced 3D games for embedded devices using OpenGL,
several issues should be considered.
Consider a game like Quake, which has been ported to multiple smart phones. This game uses
immediate mode drawing 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 can consume significant resources (especially for a game like Quake, which
has approximately 100,000 lines of source).
In OpenGL ES, geometry must be specified using vertex arrays, so the preceding code becomes
something like this:
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, ...);
You also must 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. Here 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);
The following are other differences worth mentioning:
OpenGL ES does not render polygons as wireframe or points (only solid).
There is no GLU (OpenGL Utility Library). However, it is possible to find
implementations of GLU functions on the Internet.
Search WWH ::




Custom Search