在GLSurfaceview

时间:2015-05-13 07:05:21

标签: android opengl-es transparency glsurfaceview

我创建了一个扩展GLSurfaceview的Cubeview,我想制作透明背景但不能这样做。

我已在MainActivity&中使用setZOrderOnTop() GLSurfaceview视图类中的glClearColor(),也跟随很多link ,但没有工作。

public class RubikActivity extends Activity {
cubeView cv;
GLSurfaceView gv;
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);
    cv = (cubeView) findViewById(R.id.cubeView);
    cv.initialize(PreferenceManager.getDefaultSharedPreferences(this));
    cv.requestFocus();
    cv.setFocusableInTouchMode(true);
    cv.setEGLConfigChooser(8, 8, 8, 8, 8,0); 
  //  cv.setRenderer( new CubeRenderer(getApplicationContext(), font, mWorld, rCube, mMenu, prefs);
    cv.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    cv.setZOrderOnTop(true);

}

CubeView.java

public cubeView(Context context, AttributeSet attrs) {
    super(context, attrs);
    font = new TextureFont(getContext(), R.drawable.roboto_regular, "roboto_regular_dims.txt");
    mWorld = new GLWorld();

 }

 public void initialize(SharedPreferences prefs) {

     rCube = new Rubec(mWorld, prefs.getInt("dim", 3));
     mMenu = new CubeMenu(rCube, font);
     _renderer = new CubeRenderer(getContext(), font, mWorld, rCube, mMenu, prefs);
     rCube.setRenderer(_renderer);
     mWorld.setRubeCube(rCube);
     setRenderer(_renderer);

     getHolder().setFormat(PixelFormat.TRANSLUCENT);
     setZOrderOnTop(true);
 }

CubeRenderer.java

public void onDrawFrame(GL10 g) {
    GL11 gl = (GL11)g;

    surfaceSetup(gl);

    gl.glClearColor(0,0,0,1);
    gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
}

我想透明Cubeview

1 个答案:

答案 0 :(得分:0)

您正在将屏幕清除为不透明的黑色。如果您想要透明的黑色,请将gl.glClearColor(0,0,0,1)更改为gl.glClearColor(0,0,0,0)