9

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.

PopGorn
  • 131
  • 1
  • 5

2 Answers2

1
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

Community
  • 1
  • 1
Fred Grott
  • 3,505
  • 1
  • 23
  • 18
0

setZOrderOnTop() works, but it means that you can't place any graphics on top of this SurfaceView, which is unfortunate.

Manuel Schmitzberger
  • 5,162
  • 3
  • 36
  • 45