First what is vertical syncronisation? This method is in fact rather old and was already used in old DOS games. When Vsync is turned on, the graphics card waits until the monitor has completely refreshed before it draws the next frame. The advantage of this is that the image doesn't flicker. A sideeffect is that this might cost speed.
With most old (approx. > 1999) and all new OpenGL graphics card you can set whether VSync should be turned on or not. As this functionality is optional you have to check whether the extension WGL_EXT_swap_control is supported. If it is supported you have to get the function address of wglSwapIntervalEXT(int) using wglGetProcAddress(char*). If you want to check whether VSync is on or not, use wglGetSwapIntervalEXT().
Notice that you can specify the interval of VSync'ing. If you set the interval to 1, the monitor is refreshed after one 'completed' frame. When the interval is set to 2 the monitor will be refreshed every two frames. But you will rarely need this 'precision'.
Let the coding begin!
The first function is a bit more complicated. Here we check whether switching the state of VSync'ing is supported by the graphics card's driver. If yes, the string WGL_EXT_swap_control is contained in the extensions string. Then we simply save the addresses of the two extensions functions in the approporiate function pointers. The next two functions are very straight-forward. VSyncEnabled() checks whether VSync is turned on and SetVSyncState(..) turns it on or off. Here's a little code snippet how to use it:
Easy, eh? By the way I have programmed a little helper class that exactly does this, called SGLVsync. Check it out if you don't want to know the details :-). As always: Questions? Comments? Anything Else? Message Board! Happy Coding!