Rendering Using Native OpenGL on Android - 2
We will load a jpeg file as a texture image and render it on the screen.
1. Introduction
Please check my previous post to learn how to render a simple triangle on the screen using native OpenGL on Android.
https://chuzcjoe.github.io/2024/06/19/cgv-native-opengl-android/
We will continue to use the same codebase to add textures.
You can find the source code: https://github.com/chuzcjoe/nativegl/tree/load_texture
In this project, we also need third party library(libjpeg) for loading a jpeg image and use it as our texture for rendering. For more details on how to compile libjpeg and add it to our project, please check out my another post: https://chuzcjoe.github.io/2024/06/22/misc-cross-compile-libjpeg-for-android-armv8a/
In my provided source code, I’ve included everything you need. You should be able to run it on most of the armv8a arch Android devices without any issues.
2. Details
Most part of the code should remain the same except for some additional operations to load and bind textures.
A customized function to load a jpeg.
1 | unsigned char *GLRender::loadJPEG(const char *filename, int &width, int &height) { |
Prepare and config texture.
1 | void GLRender::surfaceCreate() { |
Modify shaders.
1 | const char* vertexShader = VERTEX_SHADER( |
If you run the demo app, you should see a nice image on the entire screen. The result looks really simple, however, we managed everything with OpenGL.
Rendering Using Native OpenGL on Android - 2
http://chuzcjoe.github.io/2024/06/23/cgv-texture-render-android/