我正在尝试绘制一个3D立方体并旋转它。 它绘制并且旋转正常,但当立方体的一条线(它不是一个填充的立方体)靠近相机旋转时,它会慢慢消失,当它从相机旋转离开时,它会慢慢地再次绘制。
我尝试将相机设置得更远:
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
}
有谁知道导致消失的原因是什么? 提前谢谢。
答案 0 :(得分:1)
我最好的问题是你的物体被剪裁在相机的近剪裁平面上。这是正常的效果,它正常工作。您应该尝试更改相机属性并观察更改。