forcing a display redraw using signals

I have a multi-threaded app in which one thread handles the openGL display, and the other handles the GUI to the user. When the user changes something in the GUI, I need the openGL thread to regen the display. Is there a way to signal GLX that I want to regen the screen? Right now I’m using a clunky method of using a timer func to check a flag set by the GUI thread. The method works, but it’s not very efficient.


I would implement an interface function between the OGL thread and the GUI thread. The GUI sets the flag and invokes a redraw.
Actually pretty simple, have a look at semaphores. I assume you are coding Linux right?


I don´t know what you are writing.
If you are writing an editor, or so, than i understand, that you don´t want many redraws. In this case you should just make a while loop, that checks for a boolean variable (inside your draw-thread). If it is true, redraw your scene, and set the variable to false.
In your app-thread (GUI-thread) just set the variable to true, when you want a redraw.
(In the while-loop you should use “Sleep (50);” so that the thread doesn´t use too much processingtime.)

If you are programming a game, or some other realtimeapplication, you should just draw your scene as often as possible (at least 30 times a second). You have to do this to get the “realtime” and animations, etc. And as a sideeffect you never have to bother about redraws :wink:


If you go for the while loop is a condition variable much to prefer because it let you wait without any delay or wasted CPU cycles. Here is some information