Android:OpenGLES
lastmod 2018-08-17created 2014-03-179 edits
A summary of how to use OpenGLES on Android.
Caveats when using Opengl ES 2.0 on Android
If you just start using ES 2.0 features blindly, you will see an error log like the one below.
The error log above means 2.0 cannot be used yet; you need to set the following in the GLSurfaceView.
Print Text
How to print Text using OpenGL on Android is shown below.
Create a Text Bitmap.
Bitmap bitmap = Bitmap.createBitmap( 64, 64, Bitmap.Config.ARGB_4444 );
Canvas canvas = new Canvas( bitmap );
bitmap.eraseColor( 0 );
Paint textPaint = new Paint();
textPaint.setTextSize( 18 );
textPaint.setAntiAlias( true );
textPaint.setARGB( 0xff, 0xff, 0xff, 0xff );
textPaint.setTextAlign( Paint.Align.LEFT );
textPaint.setTextScaleX( 0.5f );
canvas.drawText( str, 0.f, 15.f , textPaint);
Bind the Bitmap to a Texture.
gl.glGenTextures( 1, mTextures, 0 );
gl.glBindTexture( GL10.GL_TEXTURE_2D, mTextures[ 0 ] );
gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST );
gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR );
gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT );
gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT );
GLUtils.texImage2D( GL10.GL_TEXTURE_2D, 0, bitmap, 0 );
bitmap.recycle();
Apply the Texture.
gl.glEnableClientState( GL10.GL_VERTEX_ARRAY );
gl.glEnableClientState( GL10.GL_TEXTURE_COORD_ARRAY );
gl.glVertexPointer( NUMBER_OF_AXIS, GL10.GL_FLOAT, 0, mImageRectVertexBuffer );
gl.glBindTexture( GL10.GL_TEXTURE_2D, mTextures[ 0 ] );
gl.glTexCoordPointer( 2, GL10.GL_FLOAT, 0, mUVBuffer );
gl.glDrawElements( GL10.GL_TRIANGLES, INDICES.length, GL10.GL_UNSIGNED_SHORT, mIndicesBuffer);
Android opengles tutorial list
See the files below.
- Android OpenGL 01 Writing the basic structure: Berabue_android_opengl_01.pdf
- Android OpenGL 02 Drawing triangles and rectangles: Berabue_android_opengl_02.pdf
- Android OpenGL 03 Applying textures: Berabue_android_opengl_03.pdf
- Android OpenGL 04 Cleaning up the basic source: Berabue_android_opengl_04.pdf
- Android OpenGL function descriptions: Berabue_android_opengl_functions.pdf
See also
classes
Favorite site
Guide
- [Recommended] OpenGL ES 2.0 on Android: Getting Started
- Android application training material 10: Graphics, 2D and 3D with OpenGL 1
- Android: about TextureView
- Android Developer OpenGL translation
- OpenGL ES 1.0 example
- Android OpenGL ES 2.0 introduction and tutorial 2
- Caveats when applying an Android Bitmap as an Opengl Texture
- [Recommended] An explanation of shader concepts
- Using a Geometry Shader in GLSL
- GPU GLSL Geometry Shader
- Putting OpenGL ES to real use
- Right-handed vs left-handed coordinate systems
- [Recommended] Android Lesson Four: Introducing Basic Texturing
- Texture loading on Android Open GL ES 2.0
- Android OpenGL ES 2.0: Render To Texture
- MultiTextureRenderer.java - opengles-book-samples
- Android example source code file (GLES20TriangleRenderer.java)
- OpenGL ES 2.0 Q&A by myself
- Drawing a triangle with Android OpenGL ES 2.0
- The OpenGL ES Shading Language
- [Recommended] Visual glBlendFunc + glBlendEquation Tool
- OpenGL ES 2.0 glDepthFunc, glBlendFunc
- Android Opengl ES: When two Texture images overlap
- Android Opengl ES: 2.0 Texture Setting
- Hello Triangle: An OpenGL ES 2.0 Example
- OpenGL ES 2.0 Shader best practices
- [Recommended] Android initial setup and drawing a triangle
- [Recommended] Drawing in Android OpenGL as if it were a 2D coordinate system
- OPENGL ES 2.0 #3. Texturing
- [Recommended] OpenGL 3D graphics using JNI
- Android OpenGL APIs (Draw, Texture, Rotate)
- OpenGL ES 2.0 Texturing (Textureing)
- Android Bitmap2Texture class - OpenGL ES 1.0 Render To Texture extension alternative
- When applying an Android Bitmap as an Opengl Texture
- Android: about Android NDK OpenGL ES LoadTexture 3
- [Recommended] Using SurfaceTexture in Android
- crossle/MediaPlayerSurface
- Capture screen of GLSurfaceView to bitmap
- 05-20 14:07:53.294: E/libEGL(25779): call to OpenGL ES API with no current context (logged once per thread)
- Android: transparent background for a 3D model, CubeRederer.java
- Making the Android GLSurfaceView background transparent
FAQ
References
Pages that link here