Game Development Reference
In-Depth Information
void surfaceCreated(GL10 gl) : This method fires when the surface is created.
Here, some initialization is performed, such as setting a translucent background
(if requested) and miscellaneous OpenGL renderer tweaking.
When the code in drawFrame() is executed many times per second, the result is two tumbling cubes
(see Figure 5-4).
Listing 5-5. Cube Renderer for the Pair of Tumbling Cubes
package opengl.scenes.cubes;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.opengles.GL10;
import opengl.jni.Natives;
import opengl.scenes.Renderer;
/**
* Render a pair of tumbling cubes.
*/
public class CubeRenderer implements Renderer {
public CubeRenderer(boolean useTranslucentBackground) {
mTranslucentBackground = useTranslucentBackground;
mNativeDraw = nativeDraw;
mCube = new Cube();
}
public void drawFrame(GL10 gl) {
/*
* Usually, the first thing one might want to do is to clear
* the screen. The most efficient way of doing this is
* to use glClear().
*/
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
/*
* Now we're ready to draw some 3D objects
*/
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -3.0f);
gl.glRotatef(mAngle, 0, 1, 0);
gl.glRotatef(mAngle * 0.25f, 1, 0, 0);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
mCube.draw(gl);
gl.glRotatef(mAngle * 2.0f, 0, 1, 1);
Search WWH ::




Custom Search