Jump to content
  • Advertisement
Sign in to follow this  
blueshogun96

OpenGL wglSwapIntervalEXT

This topic is 4617 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I was just wondering about this function called wglSwapIntervalEXT. What header file is it defined in? What version of that header file do I need to use this function? I am still using the OpenGL 1.1 headers and I honestly cant tell the difference between OpenGL 1.1 and 1.5 let alone 2.0. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
If you are working on Windows you have to use extensions to use wglSwapIntervalExt function. It is defined in wglext.h (which can be found here). You will also want to download glext.h file.
In wglext file all entry points for Windows specific extensions are declared. All such functions start with prefix wgl.
To get more info about all published extensions you can look into OpenGL Extension Registry.

wglSwapIntervalEXT is from WGL_EXT_swap_control extension. It lets you specify minimum nuber of frames before each buffer swap. Usually it is used for vertical synchronization (if you set swap interval to 1). More info about whole extension can be found here.
Before using this function you need query whether you card has support for WGL_EXT_swap_control and then obtain pointer to the function using wglGetProcAddress function.

To test for support of given extension you can use function like this:

#include <windows.h>
#include "wglext.h"

bool WGLExtensionSupported(const char *extension_name)
{
// this is pointer to function which returns pointer to string with list of all wgl extensions
PFNWGLGETEXTENSIONSSTRINGEXTPROC _wglGetExtensionsStringEXT = NULL;

// determine pointer to wglGetExtensionsStringEXT function
_wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC) wglGetProcAddress("wglGetExtensionsStringEXT");

if (strstr(_wglGetExtensionsString(), extension_name) == NULL)
{
// string was not found
return false;
}

// extension is supported
return true;
}





To initialize your function pointers you need to:

PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = NULL;

if (WGLExtensionSupported("WGL_EXT_swap_control"))
{
// Extension is supported, init pointers.
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) LogGetProcAddress("wglSwapIntervalEXT");

// this is another function from WGL_EXT_swap_control extension
wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC) LogGetProcAddress("wglGetSwapIntervalEXT");
}



Then you can use these pointers as any other pointer to function. To enable vync you can call wglSwapIntervalEXT(1), to disable it you call wglSwapIntervalEXT(0).
To get current swap interval you need to call wglGetSwapIntervalEXT().

You can find differences between various OpenGL versions in OpenGL specification (GL 2.0 specs). There's section for each version of the GL released.

[Edited by - b2b3 on November 28, 2005 5:19:04 PM]

Share this post


Link to post
Share on other sites
That was a very good answer by b2b3, and blueshogun96, you might have noticed that it's also a lot of hassle to go through before each extesion you load. I recommend GLee by benjamin bunny. One visit to the website will tell you how easy it is to use. Following your example, you just need 2 lines of code:

if (GLEE_WGL_EXT_swap_control)
wglSwapIntervalEXT (num);

where num is 1 or 0 as b2b3 mentioned.

Anyway, there are also other ways of extension loading if you prefer not to do it yourself. And if you have any more trouble, just ask! [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by deavik
I recommend GLee by benjamin bunny.


Ah well, I wrote extension loader for my engine by myself and always forget that there are things like GLee which make this much easier to use.[smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!