5
當我畫一個立方體與此代碼奇OpenGL的行爲繪製一個立方體
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(
x, y, z,
x+xp, y+yp, z+zp,
0.0f, 1.0f, 0.0f);
glBegin(GL_QUADS);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(1.0f, 1.0f,-1.0f);
glVertex3f(-1.0f, 1.0f,-1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glColor3f(1.0f,0.5,0.0f);
glVertex3f(1.0f,-1.0f, 1.0f);
glVertex3f(-1.0f,-1.0f, 1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(1.0f,-1.0f,-1.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f,-1.0f, 1.0f);
glVertex3f(1.0f,-1.0f, 1.0f);
glColor3f(1.0f,1.0f,0.0f);
glVertex3f(1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f, 1.0f,-1.0f);
glVertex3f(1.0f, 1.0f,-1.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f, 1.0f);
glColor3f(1.0f,0.0f,1.0f);
glVertex3f(1.0f, 1.0f,-1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glVertex3f(1.0f,-1.0f, 1.0f);
glVertex3f(1.0f,-1.0f,-1.0f);
glEnd();
我得到一個奇怪的cude繪圖:
和
即使沒有gluLookAt()我仍然結束一張奇怪的圖畫。
奇怪的是我在python OpenGL項目中使用了完全相同的代碼,並且沒有任何問題。所以它似乎是一個C錯誤?
它似乎也是第一個2個四邊形(綠色和橙色)沒有被繪製。
剛剛解決我自己的問題,加入: glEnable(GL_DEPTH_TEST); 我的代碼。 –
我會,但我需要更多的代表來做到這一點。 –