
please wait
|
|
|
|
glutPostRedisplay();
at the end of your display function, and that should signal that you want your display function to be called again in the next iteration.glutIdleFunc(...)
The glutIdleFunc function sets the global idle callback. Freeglut calls the idle callback when there are no inputs from the user. Usage void glutIdleFunc ( void (*func) ( void ) ); funcThe new global idle callback function Description The glutIdleFunc function specifies the function that freeglut will call to perform background processing tasks such as continuous animation when window system events are not being received. If enabled, this function is called continuously from freeglut while no events are received. The callback function has no parameters and returns no value. Freeglut does not change the current window or the current menu before invoking the idle callback; programs with multiple windows or menus must explicitly set the current window and current menu and not rely on its current setting. |
glutPostRedisplay();
at the end of your idle function. Just remember that it'll be called continuously when no events are received (which, for most applications is like 90% of the time), so timing might be important to you if you want to save cpu time / control fps.std::chrono::high_resolution_clock
is not the right clock to use (it's a wall clock) for timing the cpu - use std::clock
instead. As I understand it, the reason a wall clock is no good, is that if some other thread (an unrelated OS thing) does something, then that will be included in the time as well.std::clock
states it measures time used by the program, but time outside the application could be important to the program if animations, etc are real-time. More so like if 60 seconds passed in real time, but less time passed in the process, the animations would be slower than expected. I imagine std::clock
would be good for timing algorithms, but perhaps not animations?glutPostRedisplay()
at the end of your display function. It will set a flag to signify that you wish for your display function to be called again in the next iteration of the main loop after all events have been processed.glutIdleFunc
doesn't take any parameters, nor does it return anything. Just bind it like you would any other callback
|
|
glutPostRedisplay();
at the end of your idle function (which should be different from the display function). For complex applications, your event handling and rendering should be decoupled to avoid blocking the each other. JayhawkZombie wrote: |
---|
I imagine std::clock would be good for timing algorithms, but perhaps not animations? |
std::chrono::high_resolution_clock
so that time spent in other threads wasn't included but it did include the amount of time it's been in real time, including time outside the program's execution. Well, that's what I've done before. high_resolution_clock
, so I don't know how using std::clock
would affect that.Like "Oh, it's been so many ms since the last time this function was called, that's how much I should update my animations by", since work done on the same core as the program would cause more time to pass between that program executing and my animations may need to progress further than they would under the light load. |