views:

472

answers:

2

I'd like to display some 3d object on top of the normal 2d ui layout screen.

The 2d ui screen has background image, and GLSurfaceView is child of the content layout.

I tried the same technique of the Translucent GLSurfaceView in ApiDemos sample,

but GLSurfaceView clears all and shows black background.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"    
    android:background="@drawable/my_background_image"
>

...

<android.opengl.GLSurfaceView android:id="@+id/glview"  
    android:layout_width="fill_parent"
    android:layout_height="300px"
    android:windowIsTranslucent="true" (i'm not sure this is right)
/>
</LinearLayout>

setContentView(R.layout.main);
...
glview = (GLSurfaceView) findViewById(R.id.glview);
glview.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
glview.getHolder().setFormat(PixelFormat.TRANSLUCENT);
glview.setRenderer(this);
...
gl.glClearColor(0, 0, 0, 0);
...

Can I preserve the underlying background image in this situation?

+1  A: 

this solved it for me:

    glview = (GLSurfaceView)findViewById(R.id.glview); 

    glview.setEGLConfigChooser(8,8,8,8,16,0);

    glview.setRenderer(new MyRenderer(this));
    glview.getHolder().setFormat(PixelFormat.TRANSLUCENT);

    // this made it work for me - works only from sdk level 6 on, though....
    glview.setZOrderOnTop(true);
fabricci
A: 

Any way to make it work without the set Z order? I have other view elements on top of the GLSurfaceView. I try redrawing it with requestLayout() but that's not working either.

Jlam