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

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

In your ‘draw’ function you want glutpostredisplay and glutswapbuffers

is this in your ‘draw’ function?

sorry I don’t understand your previous reply

sorry just received the other one from you

hmmm… no it’s not… it’s inside another function to short of animate it

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.

Ok thanks all… I follow your sugestion I write another function to redraw the object and call the glutPostRedisplay and it works thanks all