Converting changeable bitmap to a "GLTexture" on Android

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 :slight_smile:

Hello,

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

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

Regards, Clay

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.