View Full Version : Help: Why can't I put glutPostRedisplay inside while loop?

02-06-2002, 02:02 AM
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);

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?


02-06-2002, 02:23 AM
In your 'draw' function you want glutpostredisplay and glutswapbuffers

02-06-2002, 02:27 AM
is this in your 'draw' function?

02-06-2002, 02:29 AM
sorry I don't understand your previous reply

02-06-2002, 02:30 AM
sorry just received the other one from you

hmmm... no it's not.. it's inside another function to short of animate it

02-06-2002, 02:31 AM
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.

02-06-2002, 02:34 AM
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.

02-06-2002, 02:57 AM
Ok thanks all.. I follow your sugestion I write another function to redraw the object and call the glutPostRedisplay and it works thanks all