0
158 Aug 09, 2003 at 21:23
typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)( int );
PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0;

void setVSync(int interval=1)
{
const char *extensions = glGetString( GL_EXTENSIONS );

if( strstr( extensions, "WGL_EXT_swap_control" ) == 0 )
return; // Error: WGL_EXT_swap_control extension not supported on your computer.\n");
else
{

if( wglSwapIntervalEXT )
wglSwapIntervalEXT(interval);
}
}


The default ‘interval’ is 1, which means VSync is on. Setting it to 0 would turn it off.

#### 14 Replies

0
101 Aug 10, 2003 at 08:33

nice snippet-idea, and nice snippet!

0
101 Aug 12, 2003 at 21:07

It’s kinda only really half using OpenGL, though. It uses wgl extensions which are (obviously) only available using windows.

I don’t see why you’d really want to turn off VSync. Yes it limits frame rate, but once you get to 60, why go higher?

0
101 Aug 12, 2003 at 21:29

for measurements.

i do that in my raytracer currently, to measure raw performance.

and, if you drop from 60fps, disabling vsync is good, as you else get 60-30-15fps, i can have everything between, too.. and there is no real difference between 50 and 60 fps.. but “jumps” from 30 to 60 to 30 to 60 to 30 to 60 are visible..

0
158 Aug 12, 2003 at 21:33

Well, during development, you would have to do optimizations and also analyize your code. Turning VSync off would tell you the real frames per second of your application.

0
101 Aug 13, 2003 at 17:57

I’ll need to find a linux way to do it!

0
101 Aug 22, 2003 at 01:36

Or you could just use your compilers profiler, because it’s going to give a hell of alot more information than the frame rate will. And in any case you shouldn’t worry about optimizing anything during developement anyway. That’s what alpha testing is for.

0
101 Aug 22, 2003 at 05:32

its still a very useful feature.. very cheap to support, so what?

0
101 Dec 29, 2004 at 10:19

hello guys…. i have some quick questions about the vsync story.
i dont know if i should start a new thread so sorry if this is the wrong place for this.

davepermen wrote:

and, if you drop from 60fps, disabling vsync is good, as you else get 60-30-15fps, i can have everything between, too.. and there is no real difference between 50 and 60 fps.. but “jumps” from 30 to 60 to 30 to 60 to 30 to 60 are visible..

i have this sometimes in my application. most of the time it runs 60fps but then sometimes 30fps appears. is this because the grafics-pipeline is not balance or something ? or has this to do with alphablending operations ?
in my project i have some alpha-blended objects. so ofcourse its the typical effect that appears with alpha-blendings sometimes ?

Die Kharrat wrote:

Well, during development, you would have to do optimizations and also analyize your code. Turning VSync off would tell you the real frames per second of your application.

i remember that i read on few boards that fps over 60fps doesnt really say something…..

so iam abit confused what is really true and what not…. :blush:

• Andy
0
158 Dec 29, 2004 at 19:05

FPS is not the optimal measure of how efficient your coding is, but is just a general measure. An FPS of more than 60 is not important in terms of the human eye, where differences between 60 and 70 for example are not noticeable to the human eye.

However, during development, most developers turn vsync off so that they have a better measure of how certain things (adding a model, blending, etc.) affect the FPS.

However, the best way to measure efficiency and to optimize your code is to use a runtime profiler, which is a “tool” for timing bits of your code. You can either write your own or use a commercial one (there might be even free open source ones). With that tool, you’ll be able to measure for example what percentage of time a portion of a code took to execute, and the maximum and minimum time peaks it took, etc.

But for general purposes, FPS can work. Here’s an article that explains why FPS is not the best way to measure efficiency or optimize code.

0
101 Dec 30, 2004 at 12:30

• Andy
0
101 Sep 19, 2005 at 13:33

err…im a newb..where do u put these lines in? to turn off vsync

0
101 Sep 19, 2005 at 16:09

Anywhere. Just make sure it runs once, and probably run that code once you have opened a window/about to.

0
101 Sep 22, 2007 at 14:07

i dont understand.. where is OpenGL?? ive only heard of it in CS and i dont know where to put the code in?? you said Anywhere and i did.. in my desktop and nothing happend? where shud i put it in?

0
167 Sep 22, 2007 at 16:12

Umm he meant anywhere *in your OpenGL program*, not anywhere in your file system =D

(Actually, should be in the initialization section of the program, not just anywhere.)