Time for action – initializing OpenGL ES
Let's rewrite our
GraphicsManager
to initialize an OpenGL ES context:
Modify
jni/GraphicsManager.hpp
by performing the following:Include
EGL/egl.h
to bind OpenGL ES to the Android platform andGLES2/gl2.h
to render graphicsAdd a method
stop()
to unbind the OpenGL rendering context and free graphics resources when you're leaving the activityDefine
EGLDisplay
,EGLSurface
, andEGLContext
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
Reimplement
jni/GraphicsManager.cpp
by replacing the previous code...