Disabling vsync in OpenGL using GLX

November 10, 2014 in C, Code Snippets, gpu, OpenGL, Programming, Source Code, Tips & Tricks by admin

openglQuick code snippet about disabling VSync with GLX, using glXSwapIntervalEXT, glXSwapIntervalMESA or glXSwapIntervalSGI  functions.

For more information ,follow this link.

PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
    PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA;
    PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;

    glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalEXT");

    if (glXSwapIntervalEXT != NULL) {
        glXSwapIntervalEXT(dpy, win, 0);
    } else {
        glXSwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalMESA");
        if ( glXSwapIntervalMESA != NULL ) {
            glXSwapIntervalMESA(0);
        } else {
            glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalSGI");
            if ( glXSwapIntervalSGI != NULL ) {
                glXSwapIntervalSGI(0);
            }
        }
    }