Initializing OpenGL ES 2 on Android
Initialization of OpenGL on Android is straightforward when compared to Windows. There are two possibilities to create an OpenGL rendering context in the Android NDK: use EGL API (http://en.wikipedia.org/wiki/EGL_(API)) from NDK directly, or create a wrapper Java class based on android.opengl.GLSurfaceView
. We will choose the second option.
Getting ready
Make yourself familiar with the interface of the GLSurfaceView
class at http://developer.android.com/reference/android/opengl/GLSurfaceView.html.
How to do it…
We extend the
GLSurfaceView
class in the following way:public class GLView extends GLSurfaceView { …
The
init()
method selects theRGB_888
pixel format for a frame buffer:private void init( int depth, int stencil ) { this.getHolder().setFormat( PixelFormat.RGB_888 ); setEGLContextFactory( new ContextFactory() ); setEGLConfigChooser(new ConfigChooser( 8, 8, 8, 0, depth, stencil ) ); setRenderer( new Renderer() ); }
This inner class...