iDevGames Forums
Enabling vsync with Pygame/PyOpenGL - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Enabling vsync with Pygame/PyOpenGL (/thread-2974.html)



Enabling vsync with Pygame/PyOpenGL - cecilkorik - Oct 28, 2007 02:50 PM

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.


Enabling vsync with Pygame/PyOpenGL - OneSadCookie - Oct 28, 2007 03:04 PM

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


Enabling vsync with Pygame/PyOpenGL - manifest020 - Feb 19, 2010 09:21 PM

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!!"


Enabling vsync with Pygame/PyOpenGL - AnotherJake - Feb 20, 2010 12:42 AM

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


Enabling vsync with Pygame/PyOpenGL - manifest020 - Apr 12, 2010 07:40 PM

Thanks AnotherJake. Yes, bots and stupid people ruin it for the rest of us. Thanks for the awesome response and the job you do.