Android的,透明的子GLSurfaceView的布局?布局、透明、Android、GLSurfaceView

2023-09-06 00:25:13 作者:情似饭岛爱相随

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

我想在普通2D UI布局屏幕上方显示一些3D对象。

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

二维UI屏幕有背景图像和GLSurfaceView是内容布局的孩子。

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

我试了半透明GLSurfaceView的ApiDemos样品相同的技术,

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

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

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

我可以pserve底层背景图片$ P $在这种情况呢?

Can I preserve the underlying background image in this situation?

推荐答案

这解决了我:

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