opengl overlay on camera view

[亡魂溺海] 提交于 2019-12-04 12:38:58

问题


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


回答1:


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);     
}



回答2:


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



来源:https://stackoverflow.com/questions/8986437/opengl-overlay-on-camera-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!