1
我有6個立方體加入如下面的圖片:openGL的:繪製多個立方體GL_CULL_FACE問題
但是,當我旋轉。問題的背後立方體不包括在前面立方體
雖然我使用:
gl.glEnable(GL10.GL_CULL_FACE); // Enable cull face
gl.glCullFace(GL10.GL_BACK); // Cull the back face (don't display)
這是我的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;
}
你拯救了我的生命@derhass。非常感謝! 只需使用:gl.glEnable(GL10.GL_DEPTH_TEST);它的功能就像一個魅力! :) –