change display for 10 seconds

hi, im wondering how i can change something in the display, and make that change for 10 seconds, then go back to the default.

i thought this would work, but it doesnt. it just freezes up my computer:

if ( key == ‘b’ || key == ‘B’ )
{
top = 0.2;
sleep(20);
top = 0.0;
}

What is key? Where is it set? How is it cleared?

Does it ever get ‘b’ or ‘B’ cleared from it after entering your if statement?

I am assuming what you have is a loop to read the keyboard.

This is not really OpenGL stuff, and you’ve really not provided enough info for anyone to help you constructively.

sorry,

yeah its inside of a keyboard method which is called by
glutKeyboardFunc( keyboard );

void keyboard( const unsigned char key, const int h, const int v )
{
top = 0.0;
if ( key == ‘b’ || key == ‘B’ )
{
top = 0.2;
sleep(20);
top = 0.0;
}

{
top = 0.2;
sleep(20);
top = 0.0;
}

This code does not do any rendering. You just set a variable, wait and set it back. You need a bit more complex logic to achieve your goal.

Jan.

What you are really asking is how to do animation in OpenGL. In other words, how does one make OpenGL do computations and update the display automatically instead of in response to a key being pressed? In your case you want OpenGL to change the color of an object, count to 10 seconds, then change the color back. This is the same thing as asking OpenGL to rotate a teapot automatically instead of in response to a key being held down on the keyboard. For OpenGL animation (using GLUT) look up glutIdleFunc. For keeping track of when 10 seconds has elapsed see glutGet(GLUT_ELAPSED_TIME).