Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I want the background of the GLSurfaceView to be transparent and see the image behind.

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.

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. I've parsed all the other topics, but none of them gave me any satisfying answer.

like image 728
PopGorn Avatar asked Nov 27 '13 16:11

PopGorn


1 Answers

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

like image 60
Fred Grott Avatar answered Oct 15 '22 17:10

Fred Grott