Draw a bitmap using Opengl es on Android

I have an Android app that draws an 800 * 480 image on the screen. My phone is also 800 * 480 pixels. The phone is capable of drawing in about 25 ms. Every few seconds I want to switch to another image, which is also 800 * 480, fading out the alpha of the first image and increasing the alpha of the second image. In this case, the call to drawable.draw (canvas) takes about 75 ms.

What can I do to reduce the drawing time in the transition phase? I have considered using OPENGL, but I cannot figure it out.

+4
source share
2 answers

I had the same problem and found my work in opengl. This lesson started me: http://obviam.net/index.php/texture-mapping-opengl-android-displaying-images-using-opengl-and-squares/

+3
source

Here is a simple example of using OpenGL ES 1.0/1.1 and texture to draw a bitmap before GLSurfaceView .

  private static class BitmapRenderer implements GLSurfaceView.Renderer { private int[] textures; private Resources resources; public BitmapRenderer(Resources resources) { this.resources = resources; } private static final float[] VERTEX_COORDINATES = new float[] { -1.0f, +1.0f, 0.0f, +1.0f, +1.0f, 0.0f, -1.0f, -1.0f, 0.0f, +1.0f, -1.0f, 0.0f }; private static final float[] TEXTURE_COORDINATES = new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; private static final Buffer TEXCOORD_BUFFER = ByteBuffer.allocateDirect(TEXTURE_COORDINATES.length * 4) .order(ByteOrder.nativeOrder()).asFloatBuffer().put(TEXTURE_COORDINATES).rewind(); private static final Buffer VERTEX_BUFFER = ByteBuffer.allocateDirect(VERTEX_COORDINATES.length * 4) .order(ByteOrder.nativeOrder()).asFloatBuffer().put(VERTEX_COORDINATES).rewind(); @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { textures = new int[1]; gl.glEnable(GL10.GL_TEXTURE_2D); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glGenTextures(1, textures, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher), 0); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); } @Override public void onDrawFrame(GL10 gl) { gl.glActiveTexture(GL10.GL_TEXTURE0); gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, VERTEX_BUFFER); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, TEXCOORD_BUFFER); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4); } } 

Then just use Renderer in GLSurfaceView

 glSurfaceView.setEGLContextClientVersion(1); glSurfaceView.setRenderer(new BitmapRenderer(getResources())); glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); 

Hope this would be helpful.

+2
source

All Articles