opengl - GLUT animation with glutPostRedisplay -


is there difference between calling glutpostredisplay() @ end of display function , using idle function callback nothing call display function? have seen both ways used in examples , cannot tell difference observation.

a main loop looks this:

  1. process , handle events

    calling stuff glutkeyboardfunc/glutmousefunc.

  2. advance/update 3d state (physics/animation etc)

    typically in glutidlefunc

  3. re-draw scene if needed

    use glutdisplayfunc

glutpostredisplay sets flag, tells glut call display callback on next loop iteration. doesn't call display [1] [2].

if have game, updates every frame might not useful. maybe if you're alt-tabbed or dragging window don't need calling display. or might frame limiting dropping frames (although i'd suggest this).

void idle() {     ...     animatedthing.value += deltatime     glutpostredisplay(); //scene changing. call display } 

having "dirty" flag becomes more useful when don't need re-render continuously. maybe in 3d modelling package there isn't animation , move camera occasionally. or gui need update when hover , click on stuff.

void mousedown(int button, int state, int x, int y) {     if (clickedgui(x, y))         glutpostredisplay(); }  void idle() {     ...     if (mykeys[move_view_forward])     {         view.z -= deltatime;         glutpostredisplay();     } } 

anyway, to answer question, no, there's not difference. however...

  1. i'd put glutpostredisplay in idle above. calling within display works gives control might want later. it's this:

    bool shoulddraw = true; while (1) {     // check events, input etc      // idle/update state      if (shoulddraw)     {         shoulddraw = false;         // draw         shoulddraw = true;     } } 
  2. i wouldn't call display idle design perspective removes control glut. example if there's case glut needs override post-redisplay (not know of one) won't able to.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -