[英]How can I put a view on top of a glSurfaceView with a transparent background?
My app is composed (from back to front) of an image background, then a glSurfaceView containing a 3D object and on the top 2 buttons. 我的应用程序由图像背景组成(从后到前),然后是包含3D对象和前2个按钮的glSurfaceView。 I want the background of the GLSurfaceView to be transparent and see the image behind. 我希望GLSurfaceView的背景是透明的,并看到背后的图像。
I've tried two solutions, but none of them is satisfying : 我尝试了两种解决方案,但没有一种令人满意:
mGLSurfaceView = new GLSurfaceView(mContext);
mGLSurfaceView.setEGLContextClientVersion(2);
mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
mGLSurfaceView.setZOrderOnTop(true);
mGLSurfaceView.setRenderer(mRenderer);
In this case, I can see the background, but the 3D object is floating on the top of all the other layouts, sometimes hiding the buttons. 在这种情况下,我可以看到背景,但3D对象浮动在所有其他布局的顶部,有时隐藏按钮。
mGLSurfaceView = new GLSurfaceView(mContext);
mGLSurfaceView.setEGLContextClientVersion(2);
mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
mGLSurfaceView.setZOrderMediaOverlay(true);
mGLSurfaceView.setRenderer(mRenderer);
In that case, I can see the buttons, but the GLSurfaceView is no longer transparent and I cannot see the image background. 在这种情况下,我可以看到按钮,但GLSurfaceView不再透明,我看不到图像背景。 I've parsed all the other topics, but none of them gave me any satisfying answer. 我已经解析了所有其他主题,但没有一个给我任何令人满意的答案。
final GLSurfaceView glView = (GLSurfaceView) findViewById(R.id.glView);
glView.setZOrderOnTop(true);
glView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
glView.getHolder().setFormat(PixelFormat.RGBA_8888);
glView.setRenderer(new MyRenderer());
glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
given by SO post: Android GLSurfaceView transparent background without setZOrderonTop and the original blog post: How to set a transparent GLSurfaceView 由SO发表: Android GLSurfaceView透明背景,没有setZOrderonTop和原始博客文章: 如何设置透明的GLSurfaceView
setZOrderOnTop()有效,但这意味着你不能在这个SurfaceView上放置任何图形,这是不幸的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.