How to get SwapBuffers to wait for vsync?

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!

With GLX (X11), uses extension GLX_SGI_video_sync
With Mac (CGL, Carbon and Cocoa), set swap internal to a none zero value:…1987-CH216-SW12

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):
export __GL_SYNC_TO_VBLANK=1

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?

Thanks again!

CGLGetCurrentContext() returns the current rendering context for the calling thread.…tCurrentContext

Thanks, it works!! Thanks also for the CGL manual link…
Much appreciated.

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);