Game Development Reference
In-Depth Information
2.
The init() method selects the RGB_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() );
}
3.
This inner class performs EGL calls to create an OpenGL rendering context:
private static class ContextFactory implements
GLSurfaceView.EGLContextFactory
{
private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
public EGLContext createContext( EGL10 egl,
EGLDisplay display, EGLConfig eglConfig )
{
int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION 2,
EGL10.EGL_NONE };
EGLContext context = egl.eglCreateContext(
display, eglConfig, EGL10.EGL_NO_CONTEXT,
attrib_list );
return context;
}
public void destroyContext( EGL10 egl,
EGLDisplay display, EGLContext context )
{
egl.eglDestroyContext( display, context );
}
}
4.
The ConfigChooser class deals with pixel formats. We omit all error checks here in
the topic; however, a more robust implementation can be found in the GLView.java
ile of the 2_OpenGLES2 example:
private static class ConfigChooser implements
GLSurfaceView.EGLConfigChooser
{
public ConfigChooser( int r, int g, int b, int a,
int depth, int stencil )
private static int EGL_OPENGL_ES2_BIT = 4;
 
Search WWH ::




Custom Search