Search code examples
androidcameraglsurfaceview

GLSurfaceView display abnormal with many small cells after relaunching the Android Camera


Using the GLSurfaceView to display camera preview data, i got the abnormal preview(as the following screenshot) if i do the following operations:

  1. launch app and open camera
  2. press the HOME key
  3. re-launch app and open camera

enter image description here


Solution

  • Finally, i found the solution as following:

    In the CameraGLRender, which implements GLSurfaceView.Renderer, do something in the onSurfaceChanged

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrthof(0, width, 0, height, -10f, 10f);
        gl.glViewport(0, 0, width, height);
        // ...
    }
    

    It works fine.