How to enable/force VSYNC ?

Is there any code to enable vsync in openGL? The program has to start in vsync, platform independent.

If this is not possible (which I hope not) are there any other methods to force vsync?

It is possible, but the exact code depends on the windowing system or the lib used for it. Just like swapbuffers is not stricly opengl and depends on windowing system.

windows: wglSwapInterval(1);
SDL: search for SDL_GL_SWAP_CONTROL
linux: glXSwapInterval
etc…

Dylan:
Is there any code to enable vsync in openGL? The program has to start in vsync, platform independent.
On Linux, __GL_SYNC_TO_VBLANK=1 in the environment will trigger this on NVidia. Can’t speak for Windows.

For Windows this is the code you are probably
looking for!

HEADER FILE:
/VSync******/
typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)( int );
extern PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT;
/**************************************************/

SOURCE FILE
static inline void init_EXT_Vsync()
{
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)extgl_GetProcAddress( “wglSwapIntervalEXT” );
}

Cheers!
Rod

P.S: Don’t forget to query if extension is supported by checking in GL Extensions string before calling init_EXT_Vsync().

Afterwards, wglSwapIntervalEXT(1) will turn Vsync on.
wglSwapIntervalEXT(0) will turn it off. :slight_smile:

Thank you all very much!