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:
process , handle events
calling stuff
glutkeyboardfunc
/glutmousefunc
.advance/update 3d state (physics/animation etc)
typically in
glutidlefunc
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...
i'd put
glutpostredisplay
inidle
above. calling withindisplay
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; } }
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
Post a Comment