我正在尝试在我的棋盘地板上添加墙壁,以便它们形成一个立方体,我已经有了底部,但我很难画出背面或墙壁。
这是我的代码:
class Checkerboard {
int displayListId;
int width;
int depth;
public:
Checkerboard(int width, int depth): width(width), depth(depth) {}
double centerx() {return width / 2;}
double centerz() {return depth / 2;}
void create() {
displayListId = glGenLists(1);
glNewList(displayListId, GL_COMPILE);
GLfloat lightPosition[] = {4, 3, 7, 1};
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glBegin(GL_QUADS);
glNormal3d(0, 1, 0);
for (int x = 0; x < width - 1; x++) {
for (int z = 0; z < depth - 1; z++) {
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE,
(x + z) % 2 == 0 ? RED : WHITE);
glVertex3d(x, 0, z);
glVertex3d(x+1, 0, z);
glVertex3d(x+1, 0, z+1);
glVertex3d(x, 0, z+1);
}
}
glEnd();
glEndList();
}
void draw() {
glCallList(displayListId);
}
}
;
我正在尝试添加以下代码:
glColor3f(1.0f,1.0f,0.0f); // Color Yellow
glVertex3d( 1.0f,-1.0f,-1.0f); // Top Right Of The Quad (Back)
glVertex3d(-1.0f,-1.0f,-1.0f); // Top Left Of The Quad (Back)
glVertex3d(-1.0f, 1.0f,-1.0f); // Bottom Left Of The Quad (Back)
glVertex3d( 1.0f, 1.0f,-1.0f); // Bottom Right Of The Quad (Back)
有人可以指出我做错了什么吗?