Game Development Reference
In-Depth Information
The Basic Android Java OpenGL Framework
In this section, I cover the basic Android Java OpenGL framework that is the basis for all OpenGL
related applications, including games. I first cover the basic framework for a program with a single
OpenGL view. Next, I cover a framework that contains multiple views that include an OpenGL view
as part of the user interface.
Basic Android OpenGL ES Framework for a Single-View OpenGL
ES Application
In this section, I will discuss how to create an OpenGL ES 2.0 Android application where there is
only a single OpenGL ES 2.0 view. I first discuss a customized GLSurfaceView class. Then I discuss
the custom renderer we need to do the actual drawing of the 3D OpenGL ES objects.
The Custom GLSurfaceView
In order to create your own custom OpenGL ES-based games, you have to create a custom
GLSurfaceView , a custom Renderer that draws this custom GLSurfaceView , and then set this new
custom GLSurfaceView as the main view through the setContentView() function in your custom
Activity class.
The custom GLSurfaceView object must be notified when the Activity is paused or resumed. This
means that the onPause() and onResume() functions in the GLSurfaceView object must be called
when onPause() or onResume() is called in the Activity.
In the custom MyGLSurfaceView class below, which is derived from the GLSurfaceView class, you also
have to set the OpenGL ES version to use to 2.0 by calling setEGLContextClientVersion(2) inside the
constructor. You must also set your custom renderer, which is MyGLRenderer in the example below,
using the setRenderer(new MyGLRenderer()) statement, also in the constructor. See Listing 2-2.
Listing 2-2. Activity Class for a Single OpenGL ES View Application
package robs.demo.robssimplegldemo;
import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
public class RobsSimpleOpenGLDemoActivity extends Activity
{
private GLSurfaceView m_GLView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
 
Search WWH ::




Custom Search