Game Development Reference
In-Depth Information
GLGraphics(GLSurfaceView glView) {
this
.glView = glView;
}
public
GL10 getGL() {
return
gl;
}
void
setGL(GL10 gl) {
this
.gl = gl;
}
public int
getWidth() {
return
glView.getWidth();
}
public int
getHeight() {
return
glView.getHeight();
}
}
This class has just a few getters and setters. Note that we will use this class in the rendering
thread set up by the
GLSurfaceView
. As such, it might be problematic to call methods of
a
View
, which lives mostly on the UI thread. In this case, it's OK, as we only query for the
GLSurfaceView
's width and height, so we get away with it.
The
GLGame
class is a bit more involved. It borrows most of its code from the
AndroidGame
class.
The synchronization between the rendering and UI threads is a little bit more complex. Let's have
a look at it in Listing 7-3.
Listing 7-3. GLGame.java, the Mighty OpenGL ES Game Implementation
package
com.badlogic.androidgames.framework.impl;
import
javax.microedition.khronos.egl.EGLConfig;
import
javax.microedition.khronos.opengles.GL10;
import
android.app.Activity;
import
android.content.Context;
import
android.opengl.GLSurfaceView;
import
android.opengl.GLSurfaceView.Renderer;
import
android.os.Bundle;
import
android.os.PowerManager;
import
android.os.PowerManager.WakeLock;
import
android.view.Window;
import
android.view.WindowManager;
import
com.badlogic.androidgames.framework.Audio;
import
com.badlogic.androidgames.framework.FileIO;
import
com.badlogic.androidgames.framework.Game;
import
com.badlogic.androidgames.framework.Graphics;