Reputation: 183
I run the code below in display()
but the object tree
didn't show. Anything wrong about the for
loop? Do i need to put any header file to exucute for loop ?
tree(float f){
// CODE CREATED OBJECT,NO PROBLEM HERE
}
void display()
{
for (int i=216;i>=317;i++) //PROBLEM HERE,FOR LOOP NOT EXECUTED
{
glPushMatrix();
glTranslated(i, 6.8, -5.3);
glScaled(0.2, 0.2, 0.2);
tree(3.5);
glPopMatrix();
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(screenWidth, screenHeight);
glutCreateWindow("Unexpected Adventure");
initRendering();
glutDisplayFunc(display);
glutReshapeFunc(handleResize);
glutIdleFunc(idle);
glutKeyboardFunc(keyboard);
init();
initGL();
glutMainLoop();
}
Upvotes: 0
Views: 32
Reputation: 29264
I recommend always loop from 0 to n
times, and do the math inside the loop
for (int i=0; i<100; i++)
{
glPushMatrix();
float x = 216 + i;
glTranslated(x, 6.8, -5.3);
glScaled(0.2, 0.2, 0.2);
tree(3.5);
glPopMatrix();
}
Upvotes: 1