Reputation: 1
I am creating simple 10x10 maze using gl_line_strip. i have two kinds of shapes regarding of random number generated. Problem is that it allways generates same random number(in my case zero)
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();}
Upvotes: 0
Views: 4801
Reputation: 3172
a = myArray[(rand() % 2)];
Here is your problem : a is an int, myArray contains only doubles < 0.5, so the affectation means rounding, so all your results are 0. You have to change the type of a to double
.
Upvotes: 2