songeb
February 6, 2002, 2:02am
1
Hi all,
I try to put glutPostRedisplay inside a for loop or while loop but I doesn’t work example
for (int k=0; k<5; k++)
{ translate +=5;
glTranslatef(translate, 0.0, 0.0);
glutPostRedisplay();
}
It doesn’t work… this will only be redisplayed after the last iteration. What I want is every iteration it’s displayed. Can anyone help me?
regards,
songeb
Gavin
February 6, 2002, 2:23am
2
In your ‘draw’ function you want glutpostredisplay and glutswapbuffers
Gavin
February 6, 2002, 2:27am
3
is this in your ‘draw’ function?
songeb
February 6, 2002, 2:29am
4
sorry I don’t understand your previous reply
songeb
February 6, 2002, 2:30am
5
sorry just received the other one from you
hmmm… no it’s not… it’s inside another function to short of animate it
athlon
February 6, 2002, 2:31am
6
the problem is, that glutPostRedisplay works “parallel” to the rest of the program. And the code in the while loop is executet faster than the glutPostRedisplay.
A solution would be to implement this code in the Idel-function of Glut.
You have to separate your drawing code from your timing code.
Create a Draw() method that will draw all your geometry for a scene at the ‘current’ time, where ‘current’ is determined when starting the Draw().
Then also activate the GLUT Idle callback, and inside that callback do a glutPostRedisplay().
Do your transforms and other time-dependent changes at the beginning of Draw(), based on the current time and/or the amount of elapsed time.
songeb
February 6, 2002, 2:57am
8
Ok thanks all… I follow your sugestion I write another function to redraw the object and call the glutPostRedisplay and it works thanks all