远处的物体在附近重叠。为什么这样,我该如何解决?

时间:2012-04-16 14:28:46

标签: c++ visual-c++ opengl

这是输出的样子: Screenshot of objects overlapping

我的代码是:

(...)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor3f(1.0f, 1.0f, 1.0f);
glTranslatef(-10,0,0);
glRotatef(-17.14f,0,1,0);

////////////////////////////////////////////////////////////////////
for(int i=1;i<=21;i++){
    glTranslatef(10,0,0);
    glRotatef(17.14f,0,1,0);

    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
    glTexCoord2f(1.0f, 0.0f);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
    glTexCoord2f(1.0f, 1.0f);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
    glTexCoord2f(0.0f, 1.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
    glEnd();

}
(...)

它基本上是一个旋转的图像磁盘(稍后会更改它们)。

1 个答案:

答案 0 :(得分:3)

启用depth buffering