OpenGL goes to sleep

Hi Everyon,

I am running a piece of openGL code on a windows machine and need to flick between the openGL application and another application as they communicate between each other. When I am using the other application, the openGL code seems to go asleep. I need to see the changes made in the other app in my openGL window in real time, so having to switch application and click on my openGL window is not good.

Is there some option in openGL which you can switch to stop the code going “asleep” and forcing the user to click again on the openGL window?

Any help much appreciated,

Regards,

Kris.

Assuming you are using Windows, read the documentation for SetThreadExecutionState.

Are you using GetMessage or PeekMessage for your main loop? I suspect the former, as the behaviour of GetMessage is to block until a message is available, but with the app not having focus it will likely not be receiving any messages anyway. Hence the apparent "sleep"ing.

If this is the case then I’d recommend switching to PeekMessage instead. There’s a pretty good sample loop here. Note that by default this will chew your CPU, so you might want to add a Sleep (5) call to the loop to prevent this if it’s not desirable behaviour for your program.

You might also consider using SetTimer() to periodically post WM_TIMER messages to the window message queue. When you get a WM_TIMER message, use InvalidateRect() to tee up a repaint.

This will allow you to block in GetMessage, avoiding CPU burn, but still redraw periodically.

MsgWaitForMultipleObjects() can be used to do more complicated blocks, perhaps combined with CreateWaitableTimer(), waking up either for message input or other events (then you would use PeekMessage to consume all the messages).

WM_TIMER has poor resolution which might lead to jumpy framerates. But depending on the program this might not be an issue; you do need to be aware of it though.

When your OpenGL app receive message from other app, just invalidate opengl window. Use InvalidateRect call to do this.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.