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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With