View Full Version : Converting changeable bitmap to a "GLTexture" on Android

03-22-2013, 07:01 AM
I've got a question about converting bitmaps into OpenGL-textures. I used following code for loading textures yet:

private int loadTexture()
final int[] textureHandle = new int[1];

GLES20.glGenTextures(1, textureHandle, 0);

if (textureHandle[0] != 0)
// Bind to the texture in OpenGL
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

// Set filtering

// Load the bitmap into the bound texture.
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

if (textureHandle[0] == 0)
throw new RuntimeException("Error loading texture.");

return textureHandle[0];

That works fine as long as I just have to load the texture once. But, in my case the bitmap is changed for every frame through drawing on it via a canvas. How can I update the texture efficiently, because loading the texture every time is really low-performance and crashs when the system is running out of memory.?

Thx Vaio
PS: Sorry for my english, I'm not a native speaker :)

03-25-2013, 03:38 PM

What you are trying to do is called texture streaming, which OpenGL ES does not support directly. But, I recently wrote some articles on OpenGL ES which will help. The first one shows how to use EGL Image extensions on Android to transfer images into OpenGL ES textures fast:

http://software.intel.com/en-us/article ... cy-2d-guis (http://software.intel.com/en-us/articles/using-opengl-es-to-accelerate-apps-with-legacy-2d-guis)

And this article details the pitfalls of using the Android Bitmap class with OpenGL ES:

http://software.intel.com/en-us/article ... ors-part-1 (http://software.intel.com/en-us/articles/porting-opengl-games-to-android-on-intel-atom-processors-part-1)

Regards, Clay