This topic is about setting up and using OpenGL ES 2.0+ on Android. OpenGL ES is the standard for 2D and 3D accelerated graphics on embedded systems - including consoles, smartphones, appliances and vehicles.
Setting up GLSurfaceView and OpenGL ES 2.0+
To use OpenGL ES in your application you must add this to the manifest:
Create your extended GLSurfaceView:
Add MyGLSurfaceView to your layout:
To use newer version of OpenGL ES just change the version number in your manifest, in the static import and change setEGLContextClientVersion.
Compiling and Linking GLSL-ES Shaders from asset file
The Assets folder is the most common place to store your GLSL-ES shader files. To use them in your OpenGL ES application you need to load them to a string in the first place. This functions creates a string from the asset file:
Now you need to create a function that compiles a shader stored in a sting:
Now you can load, compile and link your shaders:
If there are no errors, your shader program is ready to use:
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0