Game Development Reference
In-Depth Information
Java Main Activity
When the user starts the application, the JavaGLActivity.onCreate() method will be called
(see Listing 3-5). Here is where the surface view ( mGLSurfaceView ) is initialized and set as the
application content:
mGLSurfaceView = new GLSurfaceView(this);
mGLSurfaceView.setRenderer(new CubeRenderer(true));
setContentView(mGLSurfaceView);
Note that the GL surface view must use a renderer ( CubeRenderer in this case), which
implements the Renderer interface and takes a Boolean argument, indicating whether a
translucent background should be used.
Listing 3-5. Main Activity for the Java-Only Version of the GL Cubes Sample
package opengl.test;
import opengl.scenes.GLSurfaceView;
import opengl.scenes.cubes.CubeRenderer;
import android.app.Activity;
import android.os.Bundle;
public class JavaGLActivity extends Activity
{
private GLSurfaceView mGLSurfaceView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLSurfaceView = new GLSurfaceView(this);
try {
mGLSurfaceView.setRenderer(new CubeRenderer(true));
setContentView(mGLSurfaceView);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onPause() {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity loses focus
super.onPause();
mGLSurfaceView.onPause();
}
 
Search WWH ::




Custom Search