我正在使用 gl_line_strip 创建简单的 10x10 迷宫。关于生成的随机数,我有两种形状。问题是它总是生成相同的随机数(在我的情况下为零)
void display(void){
glClear( GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
GLdouble myArray[2] ={0,0.1};
GLint a;
srand(time(0));
for (int i = 0; i < 10; i++)
{
glPushMatrix();
for (int i = 0; i < 10; i++)
{
glBegin(GL_LINE_STRIP);
a = myArray[(rand() % 2)];
std::cout<<a;
if(a == 0.1){
glVertex2f(0,a);
glVertex2f(a,a);
glVertex2f(a,0);
}else{
glVertex2f(0.1,a);
glVertex2f(a,a);
glVertex2f(a,0.1);}
glEnd();
glTranslatef(0.1,0,0);
}
glPopMatrix();
glTranslatef(0,0.1,0);
}
glFlush();}