-1
我正試圖在立方體後面畫一個大的多邊形,看起來像是地板。如果有任何時候背景地板落在立方體後面,它會完全消失。這裏是顯示功能,包括我想添加的背景和其中一個立方體邊。大對象在另一個較小的對象Opengl後消失?
void display(){
// Clear screen and Z-buffer
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
//background floor
glBegin(GL_POLYGON);
glColor3f( 0.5, 0.5, 0.5);
glVertex3f( 1, -0.9, 1); // x-y-z right bottom
glVertex3f( 0.6, 0.5, 1); //right top
glVertex3f(-0.6, 0.5, 1); //left top
glVertex3f(-1, -0.9, 1); //left bottom
glEnd();
// Rotate when user changes rotate_x and rotate_y
glRotatef(rotate_x, 1.0, 0.0, 0.0);
glRotatef(rotate_y, 0.0, 1.0, 0.0);
// FRONT side of cube
glBegin(GL_POLYGON);
glColor3f(1.0, 0.5, 0.0);
glVertex3f( 0.05, -0.05, -0.05);
glVertex3f( 0.05, 0.05, -0.05);
glVertex3f(-0.05, 0.05, -0.05);
glVertex3f(-0.05, -0.05, -0.05);
//I have omitted the other 5 sides
glEnd();
glFlush();
glutSwapBuffers();
}
一些截圖將是說明性的。 – datenwolf
沒有太多的繼續 - 但我建議'glEnable(GL_DEPTH_TEST)' –
我無法添加快照,因爲它是我第一次在堆棧溢出。 @BrettHale我嘗試了glEnable(GL_DEPTH_TEST),但後面的對象在立方體後面消失 – AnwarElWakil