PDA

View Full Version : Question about redraw()



franz1999
03-27-2005, 08:10 AM
I am specifically using FLTK redraw() function but I believe this question can be extended to GLUI,GLUT...
Why is it that I need an event to happen to be able to call a redraw of the screen? Let me explain better. If I am reading the state of the mouse and for each even coming from the mouse (for instance a move of the mouse) I update the screen and ask for redraw, this works fine.
Why can't I do the same making a loop and asking a redraw at the end of each loop? It would be so much easier and intuitive.
Can anyone elaborate on this issue and explain me what is the reason that redraw happens successfully only after events?
Thanks

mikael_aronsson
03-27-2005, 11:18 PM
Hi !

Because it all runs in one single thread normally, and that means that as long as you are in the loop you will not be able to redraw the OpenGL contents, the redraw is called when the main thread returns to the internal message handler and does not have any important messages pending, it will not redraw antthing until you exit the loop.

There are ways around this, for example on windows you could call InvalidateRect(...); UpdateWindow(...) to force a redraw of the window contents in he loop.

Another way is to put your code in a thread outside the main message thread, but I do not remember if Fltk has threading support.

Mikael

Mikael