As the title says really. I'd like to turn on vertical sync in PyOpenGL, but how can I do it? A fairly exhaustive web search didn't turn up anything, but maybe someone has a clever solution? I'm on OS X and I don't mind which package is used to create the window and the application loop. However, I'd rather stay away from developing a full-blown Cocoa app, for reasons discussed below.
I looked into using pyglet rather than PyOpenGL, but the only version of pyglet that runs on a 64 bit OS is an alpha release that's nearly a year old, so I don't want to use it because I'm afraid it might be abandonware. That's a shame because it actually looked much better than PyOpenGL.
On this page I found the following code. The page says it's for pygame, but it looks like it should work for Glut as well. However, when I run it (after creating a context) it just causes a segmentation fault. If anyone can give any insight into why that happens it would be great, because something like this is what I'm looking for.
import sys
def enable_vsync():
if sys.platform != 'darwin':
return
try:
import ctypes
import ctypes.util
ogl = ctypes.cdll.LoadLibrary(ctypes.util.find_library("OpenGL"))
# set v to 1 to enable vsync, 0 to disable vsync
v = ctypes.c_int(1)
ogl.CGLSetParameter(ogl.CGLGetCurrentContext(), ctypes.c_int(222), ctypes.pointer(v))
except:
print "Unable to set vsync mode, using driver defaults"
I could try pygame instead and see if this code works with that, but I found a few reports online that this code crashes with pygame as well, so I'm guessing it's something that used to work but now doesn't.
Finally, I'm aware that a solution that will work is to build a Cocoa app with PyObjC. However, there's a pretty big learning curve there, and I would end up with something that's not even close to cross-platform. This code is only for my own personal use, but I'm very concerned with maximising my probability of getting it working again if I come back to it in several years' time on a different machine. For those reasons I really don't think building a Cocoa app is something I want to get into.