On mac os x, there's a way to pass the system a function pointer that is triggered at an ideal time to start your drawing code. These are the
I'd like to understand how to do something analogous on windows. The ideal solution would:
- Call a function I specify after the previous draw loop's data becomes visible on the monitor.
- Avoid screen tearing.
- Minimize overhead such as #buffers. For example, avoid triple buffering, and possibly even avoiding double buffering if that is possible.
My current setup is to execute a busy loop that constantly calls
PeekMessage and starts a draw loop cycle every time there's no message. This is likely to result in more than 60 draw cycles per second, which is wasting CPU effort and results in calculated frames that are never displayed.
The best answer is one that allows me to do this without a third-party library (OpenGL and Win32 are definitely ok!); but it's still useful to know of open source libraries that solve this problem since I can then dive into the code myself.
Related notes: I've seen this stackoverflow page on OpenGL vsync and the the
wglSwapIntervalEXT() function. I don't think these comletely solve my problem since the
wglSwapIntervalEXT function only delays buffer swaps, and waiting for
glFinish ties up my event loop. I've also heard that it's bad practice to call
glFinish, and I don't know how it interacts with any buffers and vsync work windows is already doing for me. Maybe they are part of a full solution that I don't know of yet.