Title: opengl overlay on camera view
Tags: android;camera;opengl-es-2.0;android-camera
Question: I still haven't found a proper way to show an opengl overlay oon top of camera preview,

There's a hack, where you call

```setContentView(GLSurfaceView)
addContentView(MyCameraSurfaceView)
```

but it doesn't work properly - i.e. when you switch to anouther activity and go back, the opengl layer isnt displayed over camera preview.

there are a lot of tutorials and samples which use the above method, but it simply doesn't work as expected

does anyone know how they do it in layar


Here is the accepted answer: It looks like I've found the solution to my problem - its ```setZOrderMediaOverlay``` function, heres my code:

```private void initViews()
{
    mFrame = new FrameLayout(this);
    initCameraView();
    initGLView();
    setContentView( mFrame );
}
private void initGLView()
{
    mRenderer = new MyGLRenderer( this );
    mGLView = new GLSurfaceView(this);
    mGLView.setZOrderMediaOverlay(true);
    mGLView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    mGLView.setRenderer(mRenderer); 
    mGLView.getHolder().setFormat(PixelFormat.TRANSLUCENT);

    mFrame.addView( mGLView );      
}

private void initCameraView()
{
    mCameraSurfaceView = new CameraSurfaceView(this);
    mFrame.addView(mCameraSurfaceView);     
}
```


Here is another answer: Did you ever consider that when switching to another activity you are loosing the opengl context from the overlaying glsurface?

Comment for this answer: That is not the problem - I created both views with 150 dp margin, one right aligned, and the other left aligned, and both of thew where ok, but the camera view was over the GLSurvaceView. Luckily I think I've found the solution - see my answer.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:01/24/12', 'FavoriteCount': 4.0, 'PostTypeId': 1, 'Tags': '<android><camera><opengl-es-2.0><android-camera>', 'Title': 'opengl overlay on camera view', 'ViewCount': 3852, 'id': 8986437, 'user_AboutMe': '', 'user_AccountId': 945581.0, 'user_DisplayName': 'imbryk', 'user_Reputation': 1768.0, 'user_Views': 407.0, 'user_id': 972896.0}}