Hi,
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
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
// 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