-1
我想繪製一個3D立方體並旋轉它。 它繪製並且旋轉得很好,但是當立方體(它不是一個實心立方體)的一條線旋轉靠近相機時,它會慢慢消失,當它遠離相機旋轉時,它會再次緩慢地抽出。OpenGL C++線消失時,它旋轉接近相機
我想這將相機設置爲遠:
glTranslatef(0.0f, 0.0f, -5.0f);
但它並沒有工作,什麼也沒有顯示的窗口。
這是我的渲染功能:
void drawCube() {
glPushMatrix();
glRotatef(angle, 1, 1, 1);
glColor3f(0.0f, 0.0f, 0.0f);
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5f,-0.5f,0.0f);
glVertex3f(0.5f, -0.5f, 0.0f); //Platform front
glVertex3f(0.5f, 0.5f, 0.0f);
glVertex3f(-0.5f, 0.5f, 0.0f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5f, -0.5f, 1.0f);
glVertex3f(0.5f, -0.5f, 1.0f); //Platform in the back
glVertex3f(0.5f, 0.5f, 1.0f);
glVertex3f(-0.5f, 0.5f, 1.0f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5f, -0.5f, 0.0f);
glVertex3f(-0.5f, -0.5f, 1.0f);
glVertex3f(-0.5f, 0.5f, 1.0f);
glVertex3f(-0.5f, 0.5f, 0.0f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, -0.5f, 1.0f);
glVertex3f(0.5f, 0.5f, 1.0f);
glVertex3f(0.5f, 0.5f, 0.0f);
glEnd();
angle += 0.005f;
glPopMatrix();
}
void draw() {
//CLEARING THE SCREEN AND LOAD IDENTITY MATRIX FOR NEW DRAWINGS
glViewport(0, 0, 800, 600);
glClearColor(1.0f, 0.0f, 0.0f, 1.0f); //BACKGROUND COLOR
glClear(GL_COLOR_BUFFER_BIT); //CLEAR THE SCREEN
glLoadIdentity(); //RESET DRAWING LOCATIONS
glTranslatef(0.0f, 0.0f, -5.0f);
drawCube();
SDL_GL_SwapWindow(window.getWin()); //RENDER EVERYTHING TO THE SCREEN
}
有誰知道是什麼原因造成的消失? 在此先感謝。
你按什麼順序推矩陣?你是否在旋轉之前嘗試推動翻譯? –
@CelineNOEL是 –
你在哪裏設置投影矩陣? – genpfault