View Full Version : Drawing update (not every frame) ??
12-26-2008, 04:51 PM
I'd like to update a drawing, but not every frame, only when something happens (when data changes for example). How can I do that ? Using an idle callback is update the drawing every frame, so that's not what I want to do...
Of course, I want to see my drawing changing (like in an animation).
12-27-2008, 12:01 AM
I suggest you only redraw on your OS pain message (WM_PAINT windows, if I am not mistaken). This way, you won't redraw more often then really needed. You can also force a redraw (after the data has changed) by issuing a repaint message yourself.
12-27-2008, 04:11 AM
I was thinking of a simpler strategy using glutPostRedisplay. Every time the data changes I call glutPostRedisplay (I'm doing that after glutInit and before glutMain Loop)... You would think that should update the drawing, but that's not the case, only the last result is showing up, I get a blank screen before that...
What's happening ? I don't get it at all.
12-27-2008, 04:26 AM
thebuffalo, calling glutPostRedisplay refresh the window so your solution is correct. Take care that you still call glutSwapBuffers in your rendering function. Not doing this might explain why you see nothing.
12-27-2008, 04:56 AM
Hmmm no it's not that I'm calling glutSwapBuffers. Maybe nothing is happening because I'm doing that before glutMainLoop ? In other words I'm thinking that nothing can be drawn until glutMainLoop is called. In that case, I don't see how I can do what I want... I'm confused, that does not seem to bi a big deal, sorry if I look dumb...
12-27-2008, 05:08 AM
GLUT relies on glutMainLoop, because it is where (as the name suggests) the message loop is run. You will have to abandon GLUT if you want more control...
12-27-2008, 05:23 AM
But, it does not prevent you to redisplay when you want. For example, if you know that the camera movement is handled in the keyboard callback, just call glutPostRedisplay when view is changed. glutSwapBuffers just swap the drawn back buffer with the front buffer when using double buffering mode. You have to do this in order to display the right buffer when calling glutPostRedisplay
12-27-2008, 06:05 AM
dletozeun, can you really redisplay when you want ? I think that we can call glutPostRedisplay only in a callback function, and the number of callback functions is limited. Can you define a new callback function in GLUT to suit your specific need ?
12-28-2008, 04:23 AM
I think that we can call glutPostRedisplay only in a callback function
Yes that is what I implicitly mean, but where are you likely to modify data if not in a callback? I mean, the user could change data, using keyboard, mouse, or the program itself at regular intervals and there are callbacks to handle all these cases. But you can not register a new callback with glut and I don't know if you can handle correctly things like animation with only a idle function. Look at other libraries like GLFW (http://glfw.sourceforge.net/) which is more turned toward games. There is also Qt which I think is the best for this kind of things (thinking of application portability).
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.