Game Development Reference
In-Depth Information
// Create a MyGLSurfaceView instance and set it
// as the ContentView for this Activity
m_GLView = new MyGLSurfaceView(this);
setContentView(m_GLView);
}
@Override
protected void onPause()
{
super.onPause();
m_GLView.onPause();
}
@Override
protected void onResume()
{
super.onResume();
m_GLView.onResume();
}
}
///////////////////////////////////////////////////////////////////////////
class MyGLSurfaceView extends GLSurfaceView {
public MyGLSurfaceView(Context context) {
super(context);
// Create an OpenGL ES 2.0 context.
setEGLContextClientVersion(2);
// Set the Renderer for drawing on the GLSurfaceView
setRenderer(new MyGLRenderer());
}
}
The Custom Renderer
The custom MyGLRenderer class implements the interface for GLSurfaceView.Renderer. This means
that this class needs to implement the functions onSurfaceCreated() , onSurfaceChanged() ,
and onDrawFrame() .
The function onSurfaceCreated() is called when an OpenGL surface is created or when the EGL
context that is used for OpenGL ES rendering is lost. Put the creation and initialization of any
OpenGL objects and resources you need for your game here.
The o nSurfaceChanged() function is called whenever the OpenGL surface changes size or a new
surface is created.
The onDrawFrame() function is called when it's time to render the OpenGL surface to the Android
screen. Put code to actually render your 3D objects here.
See Listing 2-3 for the full custom renderer class implementation.
 
Search WWH ::




Custom Search