Book Image

Android NDK: Beginner's Guide

By : Sylvain Ratabouil
Book Image

Android NDK: Beginner's Guide

By: Sylvain Ratabouil

Overview of this book

Table of Contents (18 chapters)
Android NDK Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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;
          EGLDisplay mDisplay; EGLSurface mSurface; EGLContext mContext;
      
          GraphicsElement* mElements[1024]; int32_t mElementCount;
      };
      #endif
  2. Reimplement jni/GraphicsManager.cpp by replacing the previous code...