Controlling vertical sync on Mac OS X / crashes when trying to access platform-specific stuff via ctypes

Nathaniel Virgo <[email protected]> Fri, 14 Jun 2013 19:18:39 +0900
Newsgroups gmane.comp.python.opengl.user
Message-ID <CAOoZStXJ2nHuCs-87RF7Aj+B4uGJRr9QO=o2dyp5NM7t9w1nMQ@mail.gmail.com>
Hi all

I need to turn on vsync. Does anyone have a way to do this on OS X?  I
found the following code on the web, but when I run it (after creating a
Glut window) it always causes a segmentation fault:

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"

My (very uneducated) guess is that this is because CGLGetCurrentContext
returns an int, whereas CGLSetParameter expects a pointer to a struct as
its first argument. I have tried many permutations of the above code, but I
don't know enough about ctypes to be able to fix it.

>From looking at the PyOpenGL source, it looks like there's some stuff in
there that's aimed at exposing this kind of platform-specific stuff, but I
couldn't find any documentation for it. Is there a "correct" way to call
CGLSetParameter and similar functions?

By the way, I think it would be really great if a specific
platform-independent way to control vsync could be added to PyOpenGL. It's
a pretty important thing to be able to control.

Best regards,
Nathaniel

-- 
Nathaniel Virgo
http://nathanielvirgo.com

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev

_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net
_______________________________________________
PyOpenGL-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyopengl-users