Enabling vsync with Pygame/PyOpenGL
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.
If you are having trouble with tearing in pygame on OS X, give that code a try.
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.
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
Nice tip
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!!"
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!!"
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

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.
Thanks AnotherJake. Yes, bots and stupid people ruin it for the rest of us. Thanks for the awesome response and the job you do.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| GL_POINTS don't work in PyOpenGL | Nevada | 3 | 3,193 |
Feb 23, 2007 04:49 PM Last Post: akb825 |
|
| Enabling OGL fog in shaders | kordova | 7 | 4,358 |
Jul 12, 2006 10:12 AM Last Post: kordova |
|
| Enabling/Disabling | Nick | 3 | 2,449 |
Aug 25, 2004 12:37 AM Last Post: arekkusu |
|

