Search code examples
androidopengl-esandroid-cameraaugmented-reality

Display two Surface Views over each other?


Is there any way to set two surface views over each other so that, one of them to hold a CameraPreview and the other to hold OpenGL surface.

I have attempted this problem and my attempts are mentioned below in (code1 and code2)

Code 1 1- in this code, I open the camera with command mentioned in line 1 2- instantiated an object from the Render Class, and add this object to the surfaceView using setContentView()

but in this case, tha camera opens for few seconds and disaappears, then , the OpenGl object appearas.

public void surfaceCreated(SurfaceHolder holder) {

    camera = android.hardware.Camera.open(); //line 1
    //gLSurfaceView = new GLSurfaceView(this);
    //gLSurfaceView.setRenderer(new MyRender());
    //setContentView(gLSurfaceView);
}

Code 2 In this code, I instantiate both of the CameraSurface and the Render Class. and I also created a FrameLayout in the XML file. Then the camerSurface object is added to setContentView and the Render object to the FrameLayout. but this way, causes only the object added to the framelayout to be displayed.

cameraSurfacePreviewDemo = new CameraSurfacePreviewDemo(this);
    glSurfaceView = new GLSurfaceView(this);
    glSurfaceView.setRenderer(new MyRender());
    //setContentView(cameraSurfacePreviewDemo);
    //setContentView(glSurfaceView);
    //fl01.addView(glSurfaceView);
    //fl01.addView(cameraSurfacePreviewDemo);

=========================================================================================== Any provision with good tutorials for beginners in Android Camera and AndR "Augmented Reality" Or suggesting good books for both beginners in Android Camera and AndR "Augmented Reality will be highly appreciated.


Solution

  • IIRC it is impossible. Surface Views can not overlap. (There was longer explanation from Diane Hackeborn)