如何绘制立方体而不是四边形?
下面的代码在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);
}
The following code draws a labyrinth or maze in OpenGL, the result is a 2D labyrinth, what I need to do now is to draw cubes instead these quads, how can I do it?
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有原生的 opengl 方法可以绘制立方体。
所以你必须画6个四边形才能画一个立方体。
There is no native opengl method that will draw a cube.
So you will have to draw 6 quads to draw a cube.