I’m trying to do a vertical sync. I found that I need to use glXSwapInterval(1). But when I add it I get a compile error: ‘glXSwapInterval’ was not declared in this scope

What do I have to do to turn it on?

Do a:

  • nm -Do /usr/lib64/* | grep glXSwapInterval

I suspect you’re going to need glXSwapIntervalEXT. You should check for the presence of the extension too: EXT_swap_control

As for the compile-side, see the glxext.h file off the OpenGL Registry page (

If further questions, please mention which GPU and GL driver you’re using.

There isn’t a function by that name. Instead, there are three similar functions from 3 different extensions:

glXSwapIntervalEXT() from EXT_swap_control
glXSwapIntervalMESA() from MESA_swap_control
glXSwapIntervalSGI() from SGI_swap_control

The first one takes a Display* and GLXDrawable arguments in addition to the interval:

void glXSwapIntervalEXT (Display *dpy, GLXDrawable drawable, int interval);

The other two just take the interval:

int glXSwapIntervalSGI (int interval);
int glXSwapIntervalMESA(unsigned int interval);

As these are extensions, typically none of them are exported directly by the library, nor declared in the headers unless GLX_GLXEXT_PROTOTYPES is defined. Instead, you need to declare a variable of the appropriate pointer-to-function type and initialise it with the result of calling glXGetProcAddress().

You also need to explicitly check whether the extension is supported by the server, using glXQueryExtensionsString(). The fact that glXGetProcAddress() returns a non-null pointer only means that the function exists in the client library; it doesn’t mean that the server supports it.

Or you can use a library such as GLEW to handle extensions for you.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.