O'Reilly logo

Android NDK Game Development Cookbook by Viktor Latypov, Sergey Kosarevsky

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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…

  1. We extend the GLSurfaceView class in the following way:
    public class GLView extends GLSurfaceView
    {
      …
  2. The init() method selects the RGB_888 pixel format for a frame buffer:
     private void init( int depth, int ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required