7

可能重复:
Android OpenGL ES 透明背景

我想在普通的 2d ui 布局屏幕上显示一些 3d 对象。

2d ui 屏幕具有背景图像,而 GLSurfaceView 是内容布局的子级。

我在 ApiDemos 示例中尝试了与半透明 GLSurfaceView 相同的技术,

但 GLSurfaceView 清除所有并显示黑色背景。


<?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);
...

在这种情况下我可以保留底层背景图像吗?

4

1 回答 1

25

这为我解决了:

    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);
于 2010-08-24T18:26:01.567 回答