Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlay Transparent GLSurfaceview onto existing view in android?

Hi I have been trying to overlay a GLSurfaceview onto an existing view.The code below shows how I overlay. The only thing that doesnt work is the transparency of the glsurfaceview on top.

    view = new GLSurfaceView(this);

    view.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    view.getHolder().setFormat(PixelFormat.TRANSLUCENT);

    view.setRenderer(new Level1Renderer(this));

    setContentView(R.layout.test);


    addContentView(view, new LayoutParams(100,400));

I have then set the background colour in my renderer as

        gl.glClearColor(0.0f, 0.0f, 0.0f, 0);

Can someone advise me as to what I am leaving out?

like image 496
user560571 Avatar asked Apr 06 '11 10:04

user560571


2 Answers

the code is correct, you may want to add

glView.setZOrderOnTop(true);
glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

(in case your view is hidden by other view and you need it on top.)

like image 188
ılǝ Avatar answered Oct 03 '22 09:10

ılǝ


I had an issue with this too. I was trying to 'fade' my whole screen out by tweening alpha values of a view overlaying glSurfaceView (plus others). Other views all faded, but not the glSurfaceView.

I found that setZOrderMediaOverlay(true)...rather than setZOrderOnTop(true) on the glSurfaceView worked for me.

like image 30
Jon Avatar answered Oct 03 '22 11:10

Jon