Search code examples
androidsurfaceviewaugmented-reality

how to display two surfaces over each other?


I have a 3D cube and I open the camera preview, and I want to see this rotating cube displayed over the camera.

What I attempted is, inside the SurfaceChanged method of the class that implements surfaceHolder.callback, I call camera.setPreviewCallback(new PreviewCallback(){ } as follows:

public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {
.......
.......
.......
camera.setPreviewCallback(new PreviewCallback() {
        @Override
        public void onPreviewFrame(byte[] data, Camera camera) {
            // TODO Auto-generated method stub
            glSurface.setRenderer( new MyRender());
            setContentView(glSurface);
        }
    });

This code results in, displaying the camera preview for a few seconds until the surface is changed, then, the camera preview disappears and the 3D cube appears on a black background.

Is there anyway to show both surfaces?


Solution

  • As far as I recall, you have to set the CameraPreview ontop of the GlView. Thats not intuitive, but should work. here is a link that may help you: http://digitalbreed.com/2009/android-render-opengl-on-top-of-camera-preview