1

I want to do an OpenGL animation (GLSurfaceView) in front of the Camera2 API preview (TextureView), but the animation isn't transparent. I've added the GLSurfaceView in front of the TextureView.

  • it only works, if I set the setZOrderOnTop(true); in the GLSurfaceView, but then all buttons and also the drawer is behind of the the view...

Is there a way to make the the GLSurfaceView (animation) transparent?

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

2 Answers2

2

SurfaceView (and its sub-class GLSurfaceView) have two parts, the Surface and the View. The Surface provides access to a separate layer, independent of the View UI layer. You can position it in front of or behind the View layer, but it can't fit "between" Views.

Using setZOrderOnTop(true) is the correct way to place the Surface layer in front of the Views. If that's not what you want, you should consider instead using a TextureView, as those are rendered on the View layer and can be positioned above or below individual Views.

You can render to a TextureView (or anything else with a Surface) with OpenGL ES. See, for example, the "simple GL in TextureView" Activity in Grafika.

fadden
  • 51,356
  • 5
  • 116
  • 166
  • Thx for your good answer! I've used the TexturveView now, but the problem is that it isn't transparent. And also **setOpaque(false)** doesn't work... – Manuel Schmitzberger Feb 05 '16 at 09:20
  • `setOpaque(false)` is necessary (the system assumes opaque by default). Make sure you're clearing pixels with transparency, e.g. `canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR)` (note the explicit blend mode), or `glClear(0,0,0,0)`. Are you using `setAlpha()`? One answer (http://stackoverflow.com/questions/18993355/) found success by fiddling with the layout as well. – fadden Feb 05 '16 at 16:43
  • This is not possible with a TextureView. Even if you render a transparent clear color, it will be against a white background because of how Android uses texture views in its drawing system. – Manuel Schmitzberger Feb 22 '16 at 13:48
0

setZOrderOnTop() works, but it means that you cannot have anything above a transparent SurfaceView, which is unfortunate.

The only way is, to replace the TextureView of the Camera2 preview, with a SurfaceView. Then I can use the setZOrderMediaOverlay(true); in the GLSurfaceView.

setZOrderMediaOverlay(boolean isMediaOverlay)

Control whether the surface view's surface is placed on top of another regular surface view in the window (but still behind the window itself).

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