Search code examples
androidviewsurfaceviewviewgroupglsurfaceview

Is it possible to draw View or ViewGroup inside GLSurfaceView


Is it possible to draw any view inside bounded region inside GLSurfaceView or SurfaceView?

At the moment my GLSurfaceView is filled with Bitmap textures.

I want to achieve something like this

   +---------------------------------+
   |                                 |
   |         GLSurfaceView           |
   |                                 |
   |        +-------------+          |
   |        |WhateverView/|          |
   |        | Layout/     |          |
   |        |ViewGroup    |          |
   |        +-------------+          |
   |                                 |
   +---------------------------------+

I've tried doing this with FrameLayout to draw the View on the top of the GLSurfaceview, but that is not what I'm trying to achieve.

Thanks.


Solution

  • I had a same issue. I used this tricks below.

    Use AbsoluteLayout to overlap GLSurfaceView and other View.

    AbsouluteLayout -+-- GLSurfaceView
                     +-- View
    

    Set GLSurfaceView transparent.

    mGlSurfaceView.setEGLContextClientVersion(2);
    mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    mGlSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    mGlSurfaceView.setRenderer(new GLES20TriangleRenderer(this));
    mGlSurfaceView.setZOrderOnTop(true);
    

    Add a punching hole. do not render an overlapping region in GLSurfaceView. OnTouchListener that is attached to GLSurfaceView returns false in the overlapping region to propagate events to other views.

    PS: Sorry for my poor english.