我有 6 个立方体连接在一起,如下图所示:
但是当我旋转它时。问题是后面的立方体没有被前面的立方体覆盖
虽然我使用:
gl.glEnable(GL10.GL_CULL_FACE); // Enable cull face
gl.glCullFace(GL10.GL_BACK); // Cull the back face (don't display)
Run Code Online (Sandbox Code Playgroud)
这是我的 onDrawFrame 重写函数:
@Override
public void onDrawFrame(GL10 gl) {
// Clear color and depth buffers
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glFrontFace(GL10.GL_CCW); // Front face in counter-clockwise
gl.glEnable(GL10.GL_CULL_FACE); // Enable cull face
gl.glCullFace(GL10.GL_BACK); // Cull the back face (don't display)
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); // Enable texture-coords-array (NEW)
// ----- Render the Cube -----
update();
if (currentTransperent != newTransperent) {
cube.loadTexture(gl, context, newTransperent);
currentTransperent = newTransperent;
}
gl.glLoadIdentity(); // Reset the current model-view matrix
gl.glTranslatef(xPosition, yPosition, zPosition); // Translate into the screen
gl.glRotatef(angleCube, xAxis, yAxis, zAxis); // Rotate
gl.glPushMatrix();
gl.glRotatef(90.0f, 1, 0, 0);
gl.glTranslatef(0.0f, 0.0f, 1.0f);
cube.draw(gl);
gl.glPopMatrix();
gl.glPushMatrix();
gl.glTranslatef(0.0f, 0.0f, -1.0f);
cube.draw(gl);
gl.glPopMatrix();
gl.glPushMatrix();
gl.glRotatef(270.0f, 0, 1, 0);
gl.glTranslatef(0.0f, 0.0f, -1.0f);
cube.draw(gl);
gl.glPopMatrix();
gl.glPushMatrix();
gl.glTranslatef(0.0f, 0.0f, 1.0f);
cube.draw(gl);
gl.glPopMatrix();
gl.glPushMatrix();
gl.glRotatef(270.0f, 0, 1, 0);
gl.glTranslatef(0.0f, 0.0f, 1.0f);
cube.draw(gl);
gl.glPopMatrix();
gl.glPushMatrix();
gl.glRotatef(90.0f, 1, 0, 0);
gl.glTranslatef(0.0f, 0.0f, -1.0f);
cube.draw(gl);
gl.glPopMatrix();
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); // Disable texture-coords-array
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisable(GL10.GL_CULL_FACE);
angleCube += rotateSpeed;
}
Run Code Online (Sandbox Code Playgroud)