Game Development Reference
In-Depth Information
if (tellRendererSurfaceCreated) {
mRenderer.surfaceCreated(gl);
tellRendererSurfaceCreated = false;
}
if (tellRendererSurfaceChanged) {
mRenderer.sizeChanged(gl, w, h);
tellRendererSurfaceChanged = false;
}
if ((w > 0) && (h > 0)) {
/* draw a frame here */
mRenderer.drawFrame(gl);
// Call swapBuffers() to instruct the system to display
mEglHelper.swap();
}
}
// Clean up...
mEglHelper.finish();
}
// ...
private static final Semaphore sEglSemaphore = new Semaphore(1);
private EglHelper mEglHelper;
}
The GL thread makes use of the next two sections: the cube renderer to perform drawing,
rotation, and the positioning operations on the cube and the cube class, which has
information about the cube itself. Let's look at the renderer in more detail.
CubeRenderer Class
CubeRenderer is the class that renders the pair of tumbling cubes (see Listing 3-8).
It implements the Renderer interface and does some very interesting things.
The void drawFrame(GL10 gl) method does the actual drawing and gets called many times
per second. The method starts by setting the matrix mode to GL_MODELVIEW . This essentially
says to render things in a 3D perspective (model view). Next, it clears all screen buffers by
calling glLoadIdentity() .
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
Next, the perspective is translated in the z axis by three units toward the eye viewpoint
(also known as the camera).
gl.glTranslatef(0, 0, -3.0f);
 
Search WWH ::




Custom Search