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; ...

Get Android NDK Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.