7

Possible Duplicate:
Android OpenGL ES Transparent Background

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?

Community
  • 1
  • 1
shkim
  • 1,173
  • 3
  • 16
  • 24

1 Answers1

25

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);
P.Melch
  • 8,066
  • 43
  • 40
  • 2
    @P.Melch This make GlSurfaceView on top of all the views. Now I am unable to set another view over the GlSurfaceView. Is there any other way to make the GlSurfaceView transparent. – Ajay S Aug 15 '13 at 17:55
  • @P.Melch Same problem Zorder-top make other view go behind GLsurfaceview – ask4solutions Oct 08 '14 at 10:47
  • AFAIK the only way with surfaceview is to chose front or back placement. if you want to have a more complex layout, i think TextureView is the one for you ( availble starting with API 14, though) – P.Melch Oct 09 '14 at 11:54