OpenGL ES is a subset of the OpenGL computer graphics rendering application programming interface (API) designed for embedded devices such as mobile phones, tablets, and gaming consoles. OpenGL ES serves as the primary low-level graphics API for Android. It’s used for rendering 2D and 3D graphics on Android devices. Android provides GLSurfaceView, a specialized view for OpenGL ES rendering, making it easier to integrate OpenGL ES content into Android UI.
This project leverages an excellent learning resource available at https://github.com/githubhaohao/NDK_OpenGLES_3_0. Thanks the author for make it open souce. Building upon the original code, this project introduces several customizations, including the use of the more modern Kotlin language for development and modifications to some native C++ APIs to better align with the project’s requirements. Additionally, the learning approach has been slightly adjusted. The primary aim of this project is educational.
2. Environment Setup
The UI is simple. On the top right corner, we have a menu that allows us to select the GL demo we want to render on the center screen. For example, here we only have one option which is to render a triangle on the screen. As we continue to make progress, more samples will be added to the list.
3. Design
MyGLSurfaceView inherits from GLSurfaceView, configs EGL and set Render.
On the native code side, we have a GLContext class that manages the rendering context. It is designed to be singleton pattern, since we only want one instance of the context.