【发布时间】:2014-02-01 03:53:14
【问题描述】:
我正在尝试创建一个嵌套的 while 循环结构,它将创建一个 3 * 3 的立方体网格。它似乎只运行一次内部循环,用立方体创建一个“L”形。所以,我的猜测是内部 while 循环在第一次运行后并没有重置,但我确实似乎明确地重置了它。
我宁愿不发布整个代码,因为有些是我的 TA 提供的代码,未经他们的许可发布是不对的。
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
UpdateTransform();
int x = 0;
int y = 0;
float Xres = 0;
float Yres = 0;
while(x < 3)
{
glPushMatrix();
glTranslatef(Xres,0,0);
drawOneCube();
glPopMatrix();
Xres += 0.3;
while(y < 3)
{
glPushMatrix();
glTranslatef(0,Yres,0);
drawOneCube();
glPopMatrix();
Yres += 0.3;
y++;
}
y = 0;
Yres = 0;
x++;
}
glutSwapBuffers();//this prevents that problem where the window copies the contents behind the window, possibly with glClear at the top of this function
}
【问题讨论】:
标签: c++ opengl nested-loops