下面的代码在OpenGL中绘制了一个迷宫或迷宫,结果是一个2D迷宫,我现在需要做的是绘制立方体而不是这些四边形,我该怎么做?
function drawmaze() {
int x,y,dl;
glNewList(dl=glGenLists(1),GL_COMPILE);
glPushAttrib(GL_TEXTURE_BIT | GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
// glPushMatrix();
float i = 0;
for(y=0;y < mazedata.size();y++) {
for(x=0;x < mazedata[y].size();x++) {
bool dibujar = false;
if(wall(x,y)) {
glColor3ub(46,151,208);
drawable = true;
}
else
if (entry(x,y)) {
glColor3f(0.0f,0.184f,0.792f);
drawable = true;
}
else
if (mazexit(x,y)) {
glColor3f(0.811f,0.188f,0.176f);
drawable = true;
}
else
if (thing(x,y)) {
glColor3ub( 151, 204, 0 );
drawable = true;
}
else
if (visited(x,y)) {
glColor3ub( 66, 66, 66 );
drawable = true;
}
if (drawable) {
//glPushMatrix();
/*
This is a try
glTranslatef(1.0,0., 0.0f );
glutSolidCube(0.5);*/
//glPopMatrix();
glVertex3f(x+0.0f ,y+0.0f ,0.0f );
glVertex3f(x+0.0f ,y+1.0f ,0.0f );
glVertex3f(x+1.0f ,y+1.0f ,0.0f );
glVertex3f(x+1.0f ,y+0.0f ,0.0f );
// topside:
glVertex3f(x+0.0f ,y+0.0f ,1.0f );
glVertex3f(x+1.0f ,y+0.0f ,1.0f );
glVertex3f(x+1.0f ,y+1.0f ,1.0f );
glVertex3f(x+0.0f ,y+1.0f ,1.0f );
}
}
i++;
}
glEnd();
// glPopMatrix();
glPopAttrib();
glEndList();
return(dl);
}