Enabling vsync with Pygame/PyOpenGL

cecilkorik
Unregistered
 
Post: #1
I've asked a few questions on this forum without giving anything in return... so I hope someone finds this post useful.

I could not find any obvious way of enabling vsync in pygame (vsync is apparently disabled by default on OS X) So I came up with my own way using ctypes.
Code:
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"

If you are having trouble with tearing in pygame on OS X, give that code a try.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Should be c_int not c_long (yes, Tiger's headers say long; this was fixed in Leopard when 64-bit support was added).

Nice tip Smile
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2010.02
Post: #3
This code fixed vsync issue on my macbook that was recently upgraded from tiger to snow leopard. I have a lot of pyopengl code that I did not want to suck because of vsync tearing.

GMA950's are horrible graphics cards, and snow leopard has issues with it being 32-bit. I'm sure most developers would just buy new laptops and not have this issue, well, lucky you.

Thank you for this life-saving code.

P.S. idevgames, I am so tired of annoying forum registration crap like you just to post something useful that might help someone else. Could you please allow me to just insert a junk email box so we can get it over with and I can improve the information you provide! Thanks. Can you SPELL??? "Xcode" "XCODE" "XCODE!!"
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #4
manifest020 Wrote:P.S. idevgames, I am so tired of annoying forum registration crap like you just to post something useful that might help someone else. Could you please allow me to just insert a junk email box so we can get it over with and I can improve the information you provide! Thanks. Can you SPELL??? "Xcode" "XCODE" "XCODE!!"

Sorry for the inconvenience. We're sick of it too Sad

Actually, here it's worse than having to enter email -- a moderator has to approve your first few posts. This is a very actively moderated board.

The problem appears to be that there is no easy way to make sure someone isn't a spammer or a bot. I think the bots can be beaten, but there are some very persistent spammers who apparently are actual human beings who don't have anything better to do with their lives than spend time registering at forums and attempting to spew crap all over our boards. I knock out one or two of those a week. It's pretty pathetic.

Anyway, again, sorry for the inconvenience, but we're glad you took the time, and we hope you stick around. Smile
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2010.02
Post: #5
Thanks AnotherJake. Yes, bots and stupid people ruin it for the rest of us. Thanks for the awesome response and the job you do.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  GL_POINTS don't work in PyOpenGL Nevada 3 3,617 Feb 23, 2007 04:49 PM
Last Post: akb825
  Enabling OGL fog in shaders kordova 7 5,171 Jul 12, 2006 10:12 AM
Last Post: kordova
  Enabling/Disabling Nick 3 2,682 Aug 25, 2004 12:37 AM
Last Post: arekkusu