View Full Version : How to get SwapBuffers to wait for vsync?
02-03-2010, 08:45 AM
My app is running faster than the framerate of my monitor and giving a tearing effect on the frames because of that. I'd like to wait for vertical sync before calling glutSwapBuffers, but I can't seem to find the correct function to do this. Any ideas? Thanks!
02-03-2010, 10:27 AM
With GLX (X11), uses extension GLX_SGI_video_sync
With Mac (CGL, Carbon and Cocoa), set swap internal to a none zero value:
With WGL (Windows), use extension WGL_EXT_swap_control
On Linux with nVidia, you can also set some environment variable for force sync blank (or force it in the control panel):
02-03-2010, 12:03 PM
Thanks that is helpful! I'm on Mac OSX so I think I can use
CGLSetParameter(context, kCGLCPSwapInterval, &sync);
However, I am using GLUT so I don't have a context, only a Window. Any idea how to get the context from the window so I call CGLSetParameter? Or does GLUT just not allow this kind of thing and I need to use OpenGL instead of GLUT?
02-03-2010, 01:44 PM
CGLGetCurrentContext() returns the current rendering context for the calling thread.
02-05-2010, 07:31 AM
Thanks, it works!! Thanks also for the CGL manual link...
Here is the actual code, in case this help others, for Mac OS 10.6:
// a swap interval of 1 causes SwapBuffers to wait until the
// next vertical sync, avoiding possible tears in your images.
// Note that this limits your framerate to 60 fps or so,
// so don't forget to turn it OFF if you are doing render timing.
int swap_interval = 1;
CGLContextObj cgl_context = CGLGetCurrentContext();
CGLSetParameter(cgl_context, kCGLCPSwapInterval, &swap_interval);
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.