2015-05-13 86 views
1

我創建了一個Cubeview,它擴展了GLSurfaceview,我想使它透明,但不能這樣做。在GLSurfaceview中設置透明度

我已經在MainActivity中使用setZOrderOnTop() & glClearColor()在GLSurfaceview視圖類中也遵循很多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

隨機嘗試 - 'surfaceView.setEGLContextClientVersion(2); surfaceView.setZOrderOnTop(true); surfaceView.setEGLConfigChooser(8,8,8,8,16,0); surfaceView.getHolder()。setFormat(PixelFormat.RGBA_8888);' – Kiran

+0

@Kiran我有嘗試但不適合我................... n謝謝你的幫助我 –

回答

0

你清除屏幕不透明的黑色。如果您想要透明黑色,請將gl.glClearColor(0,0,0,1)更改爲gl.glClearColor(0,0,0,0)

+0

我已經嘗試過,但沒有工作,它顯示背景暗黑色,我想要完全透明而不是它。 –

+0

我也跟着這個 - http://stackoverflow.com/questions/16762633/android-glsurfaceview-transparent-background-without-setzorderontop?rq=1,但同樣的問題 –