PDA

View Full Version : change display for 10 seconds



popapez
05-07-2009, 08:53 PM
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;
}

scratt
05-07-2009, 11:00 PM
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.

popapez
05-07-2009, 11:25 PM
sorry,

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

popapez
05-07-2009, 11:28 PM
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;
}

Jan
05-08-2009, 03:44 AM
{
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.

MaxH
05-08-2009, 11:30 PM
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).