简体   繁体   English

opengl覆盖在相机视图上

[英]opengl overlay on camera view

I still haven't found a proper way to show an opengl overlay oon top of camera preview, 我仍然没有找到一个正确的方法来显示相机预览顶部的opengl叠加,

There's a hack, where you call 有一个黑客,你打电话

setContentView(GLSurfaceView)
addContentView(MyCameraSurfaceView)

but it doesn't work properly - ie when you switch to anouther activity and go back, the opengl layer isnt displayed over camera preview. 但它无法正常工作 - 即当您切换到其他活动并返回时,opengl图层不会显示在相机预览上。

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 有没有人知道他们是如何做到的

It looks like I've found the solution to my problem - its setZOrderMediaOverlay function, heres my code: 看起来我找到了我的问题的解决方案 - 它的setZOrderMediaOverlay函数, setZOrderMediaOverlay我的代码:

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

您是否考虑过在切换到另一个活动时,您正在从覆盖的glsurface中丢失opengl上下文?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM