Android GLSurfaceView透明背景

Android GLSurfaceView透明背景,android,opengl-es,Android,Opengl Es,我在项目中使用min3D库来可视化3D模型。该库基于openGL 为此,我定义了一个管理GLSurfaceView的渲染器。此时,我在我的应用程序中看到了3D模型,但曲面视图的背景是黑色的,我的目标是使其透明,这样我只能看到没有黑色背景的3D模型 min3D库示例,以及我读到的其他SO问题和信息,告诉我们实现这一点的方法是: _glSurfaceView.setEGLConfigChooser(8,8,8,8, 16, 0); _glSurfaceView.getHolder().setForm

我在项目中使用min3D库来可视化3D模型。该库基于openGL

为此,我定义了一个管理GLSurfaceView的渲染器。此时,我在我的应用程序中看到了3D模型,但曲面视图的背景是黑色的,我的目标是使其透明,这样我只能看到没有黑色背景的3D模型

min3D库示例,以及我读到的其他SO问题和信息,告诉我们实现这一点的方法是:

_glSurfaceView.setEGLConfigChooser(8,8,8,8, 16, 0);
_glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
这是:

scene.backgroundColor().setAll(0x00000000);
但是我不能让背景透明

首先,这是我的布局:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/valuesContainer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        ...        
    </LinearLayout>

    <FrameLayout
        android:id="@+id/model3d_container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/valuesContainer"/>
</RelativeLayout>
最后,这是一个片段,显示了3D模型,我正试图修改它,使其成为曲面trasnparent:

public class Obj3DView extends RendererFragment {

    private Object3dContainer rowObject3D;


    @Override
    protected void glSurfaceViewConfig() {
        // !important
        _glSurfaceView.setEGLConfigChooser(8,8,8,8, 16, 0);
        _glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    }


    /** Called when the activity is first created. */
    @Override
    public void initScene() {
        scene.backgroundColor().setAll(0x00000000);
        scene.lights().add(new Light());
        scene.lights().add(new Light());
        Light myLight = new Light();
        myLight.position.setZ(150);
        scene.lights().add(myLight);
        IParser myParser = Parser.createParser(Parser.Type.OBJ, getResources(), "com.masermic.rowingsoft:raw/row_obj",true);
        myParser.parse();
        rowObject3D = myParser.getParsedObject();
        rowObject3D.position().x = rowObject3D.position().y = rowObject3D.position().z = 0;
        rowObject3D.scale().x = rowObject3D.scale().y = rowObject3D.scale().z = 0.28f;
        // Depending on the model you will need to change the scale faceObject3D.scale().x = faceObject3D.scale().y = faceObject3D.scale().z = 0.009f;
        scene.addChild(rowObject3D);
    }

    @Override
    public void updateScene() {
        rowObject3D.rotation().x += 0.5;
        rowObject3D.rotation().z += 1;
        rowObject3D.rotation().y += 0.1;
    }
}
注意:此片段从属于min3D库的RenderFragment(扩展片段)扩展而来,这是此类中最相关的代码:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    _initSceneHander = new Handler();
    _updateSceneHander = new Handler();

    //
    // These 4 lines are important.
    //
    Shared.context(getActivity());
    scene = new Scene(this);
    Renderer r = new Renderer(scene);
    Shared.renderer(r);

    _glSurfaceView = new GLSurfaceView(getActivity());
    glSurfaceViewConfig();
    _glSurfaceView.setRenderer(r);
    _glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
}

我回答我自己的问题。经过多次搜索,我终于找到了一个有效的解决方案。只需将此调用包含在
glSurfaceViewConfig()中即可:


我已经下载了min3D库,但它没有RenderFragment!。有什么建议吗?
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    _initSceneHander = new Handler();
    _updateSceneHander = new Handler();

    //
    // These 4 lines are important.
    //
    Shared.context(getActivity());
    scene = new Scene(this);
    Renderer r = new Renderer(scene);
    Shared.renderer(r);

    _glSurfaceView = new GLSurfaceView(getActivity());
    glSurfaceViewConfig();
    _glSurfaceView.setRenderer(r);
    _glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
}
_glSurfaceView.setZOrderOnTop(true);