Android, Transparent sub-GLSurfaceView in layout?

11,467

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);
Share:
11,467
shkim
Author by

shkim

Contract Programmer

Updated on June 04, 2022

Comments

  • shkim
    shkim almost 2 years

    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?