O'Reilly logo

Android NDK Beginner's Guide - Second Edition by Sylvain Ratabouil

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

Time for action – initializing OpenGL ES

Let's rewrite our GraphicsManager to initialize an OpenGL ES context:

  1. Modify jni/GraphicsManager.hpp by performing the following:
    • Include EGL/egl.h to bind OpenGL ES to the Android platform and GLES2/gl2.h to render graphics
    • Add a method stop() to unbind the OpenGL rendering context and free graphics resources when you're leaving the activity
    • Define EGLDisplay, EGLSurface, and EGLContext member variables, which represent handles to system resources, as shown here:
      ...
      #include "Types.hpp"
      
      #include <android_native_app_glue.h>
      #include <GLES2/gl2.h>
      #include <EGL/egl.h>
      ...
      
      class GraphicsManager {
      public:
          ...
          status start();
          void stop(); status update(); private: ... int32_t mRenderWidth; int32_t mRenderHeight; ...

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