3

I'm trying to draw a square room in openGL, and I have this:

void drawWalls()
{

glColor3f(1,0,0);
glPushMatrix();
//glRotatef(0,0,0,1);
//glScalef(2,1,2);
glBegin(GL_QUADS);
/* Floor */
glVertex3f(-1,-1,-1);
glVertex3f(1,-1,-1);
glVertex3f(1,-1,1);
glVertex3f(-1,-1,1);
/* Ceiling */
glVertex3f(-1,1,-1);
glVertex3f(1,1,-1);
glVertex3f(1,1,1);
glVertex3f(-1,1,1);
    /* Walls */
glVertex3f(-1,-1,1);
glVertex3f(1,-1,1);
glVertex3f(1,1,1);
glVertex3f(-1,1,1);

glVertex3f(-1,-1,-1);
glVertex3f(1,-1,-1);
glVertex3f(1,1,-1);
glVertex3f(-1,1,-1);

glVertex3f(1,1,1);
glVertex3f(1,-1,1);
glVertex3f(1,-1,-1);
glVertex3f(1,1,-1);

glVertex3f(-1,1,1);
glVertex3f(-1,-1,1);
glVertex3f(-1,-1,-1);
glVertex3f(-1,1,-1);
glEnd();

glPopMatrix();

}

For whatever reasons, it's not drawing all of my sides! I've looked through my vector and it appears to be correct... But when you look inside, you see this:

walls

What am I doing wrong? Or if possible, is there a better way to draw a room rather than this? Thanks

4

1 回答 1

4

你的地板是顺时针定义的,而你的天花板是逆时针定义的(关于我从你的描述中暗示的法线)。启用剔除时,不会绘制每个背对相机的四边形。

为了解决这个问题,必须像这样定义地板:

(-1, -1, -1)
(-1, -1, 1)
(1, -1, 1)
(1, -1, -1)

对其他没有出现的墙做同样的事情。也只需逆时针定义它们。

于 2013-11-02T01:39:46.640 回答