旋转相机时的间隙

时间:2012-06-21 18:01:59

标签: opengl

我有一个很奇怪的问题。请看这些截图:

img1

img2

img3

img4

该对象的代码:

void prostopadloscian(float x, float y, float z, float red, float green, float blue)
{
    glBegin(GL_QUADS);
        glColor3f(red, green, blue);

        glNormal3f(-x,-y,-z);
        glVertex3f(-x,-y,-z);
        glNormal3f(x,-y,-z);
        glVertex3f(x,-y,-z);
        glNormal3f(x,-y,z);
        glVertex3f(x,-y,z);
        glNormal3f(-x,-y,z);
        glVertex3f(-x,-y,z);

        glNormal3f(-x,y,-z);
        glVertex3f(-x,y,-z);
        glNormal3f(x,y,-z);
        glVertex3f(x,y,-z);
        glNormal3f(x,y,z);
        glVertex3f(x,y,z);
        glNormal3f(-x,y,z);
        glVertex3f(-x,y,z);

        glNormal3f(-x,y,z);
        glVertex3f(-x,y,z);
        glNormal3f(-x,-y,z);
        glVertex3f(-x,-y,z);
        glNormal3f(-x,-y,-z);
        glVertex3f(-x,-y,-z);
        glNormal3f(-x,y,-z);
        glVertex3f(-x,y,-z);

        glNormal3f(-x,-y,-z);
        glVertex3f(-x,-y,-z);
        glNormal3f(x,-y,-z);
        glVertex3f(x,-y,-z);
        glNormal3f(x,y,-z);
        glVertex3f(x,y,-z);
        glNormal3f(-x,y,-z);
        glVertex3f(-x,y,-z);

        glNormal3f(x,y,z);
        glVertex3f(x,y,z);
        glNormal3f(x,-y,z);
        glVertex3f(x,-y,z);
        glNormal3f(x,-y,-z);
        glVertex3f(x,-y,-z);
        glNormal3f(x,y,-z);
        glVertex3f(x,y,-z);

        glNormal3f(-x,y,z);
        glVertex3f(-x,y,z);
        glNormal3f(-x,-y,z);
        glVertex3f(-x,-y,z);
        glNormal3f(-x,-y,-z);
        glVertex3f(-x,-y,-z);
        glNormal3f(-x,y,-z);
        glVertex3f(-x,y,-z);
    glEnd();
}
    void bed()
    {
        glPushMatrix();
            glTranslatef(-1.6, 0, 4.6);
            prostopadloscian(0.2, 0.25, 0.2, 0.35, 0.16, 0.14);
        glPopMatrix();
        glPushMatrix();
            glTranslatef(1.6, 0, 4.6);
            prostopadloscian(0.2, 0.25, 0.2, 0.35, 0.16, 0.14);
        glPopMatrix();
        glPushMatrix();
            glTranslatef(-1.6, 0, -4.6);
            prostopadloscian(0.2, 0.25, 0.2, 0.35, 0.16, 0.14);
        glPopMatrix();
        glPushMatrix();
            glTranslatef(1.6, 0, -4.6);
            prostopadloscian(0.2, 0.25, 0.2, 0.35, 0.16, 0.14);
        glPopMatrix();

        glPushMatrix();
            glTranslatef(0.0, 0.55, 0.0);
            prostopadloscian(2,0.3,5,0.85,0.85,0.95);
        glPopMatrix();
    }

我的display()函数从

开始
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0, 1.0, 1.0, 1.0); 

glEnable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
glLoadIdentity();

如何摆脱这种难看的效果?

2 个答案:

答案 0 :(得分:2)

是的,那些前列腺科医生确实看起来有点奇怪。从这些镜头中可以肯定地说,但有些事情要看:

  • 是否启用了背面剔除?
  • 如果是,您是否按正确的顺序指定顶点?
  • 你的前后剪裁平面是不是太远了?
  • 您的深度缓冲区是否有足够的位用于您正在使用的剪裁平面距离?
  • 你的法线都指向正确的方向吗? (提示:不。除非你很棘手,否则每张脸只需要一次glNormal电话。)

答案 1 :(得分:1)

如果这种影响是间歇性的,我会认为Z战斗可能正在发生。您是否尝试使用glPolygonOffset绘制桌面?