2

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.

Regs
  • 119
  • 1
  • 7

3 Answers3

1

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.

Dalinaum
  • 1,142
  • 13
  • 18
0

Try to create your own class extending GLSurfaceView, override the method draw(Canvas) and draw the view in it using the method draw(Canvas) of your view/viewgroup. It will be something like this :

public class MyGLSurfaceView extends GLSurfaceView
{
    private View myView;

    @Override
    protected void onDraw(Canvas canvas) {
        // Draw something below your view
        // Translate, rotate your canvas as you want
        myView.draw(canvas);
        canvas.restore(); // If you have translated or rotated the canvas
        // Draw something above your view
    }
}
yDelouis
  • 2,094
  • 17
  • 18
  • Actually my question is how to draw/bind (if it is possible) the view instead the bitmap on that region of that GLSurfaceView. – Regs Nov 04 '12 at 23:21
  • 1
    I think you can put your GLSurfaceView and your View in a RelativeLayout with the GLSurfaceView filling it and use margins to place the View where you want. – yDelouis Nov 05 '12 at 08:24
0

Yes, you can, because GLSurfaceView is one of the View, you can bind it into a layout with other view. But remember to set setZOrderOnTop() to false.

And remember that OpenGL in Android 2.x is not as good as in 4.x (which means that you have to workaround some issues happen in 2.x)

e7fendy
  • 176
  • 1
  • 5