always update() before draw()

really fundamental question
i’m sure it’s already well know / covered elsewhere

is update() always run once before draw()
is there any chance update() could be run twice?
or is it very stable? (i.e. there’s a main loop and it’ll always run update() once before draw())

thanks!
Elliot

i’m pretty sure there will only be one update() per draw().

i think the way it works is:

  
  
    glutIdleFunc(idle_cb);  
    glutDisplayFunc(display);  
  

that attaches idle_cb to run constantly, and display to run when glutPostRedisplay() is called. so in idle_cb you have:

  
  
void ofAppGlutWindow::idle_cb(void) {  
...  
	if(ofAppPtr)  
		ofAppPtr->update();  
  
		#ifdef OF_USING_POCO  
		ofNotifyEvent( ofEvents.update, voidEventArgs);  
		#endif  
  
	glutPostRedisplay();  
...  
}  
  

this is always happening. and when glutPostRedisplay() is called, then:

  
  
void ofAppGlutWindow::display(void){  
...  
	if(ofAppPtr)  
		ofAppPtr->draw();  
...  
}  
  

so, in other words, i don’t think it’s possible for the screen to draw until update completes.

1 Like