Jump to content


Turning VSync off in OpenGL


14 replies to this topic

#1 Dia

    DevMaster Staff

  • Administrators
  • 1120 posts

Posted 09 August 2003 - 09:23 PM

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
  {
    wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress( "wglSwapIntervalEXT" );

    if( wglSwapIntervalEXT )
      wglSwapIntervalEXT(interval);
  }
}

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

#2 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 10 August 2003 - 08:33 AM

nice snippet-idea, and nice snippet!
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#3 baldurk

    Senior Member

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 12 August 2003 - 09:07 PM

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?
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

#4 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 12 August 2003 - 09:29 PM

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..
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#5 Dia

    DevMaster Staff

  • Administrators
  • 1120 posts

Posted 12 August 2003 - 09:33 PM

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.

#6 baldurk

    Senior Member

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 13 August 2003 - 05:57 PM

I'll need to find a linux way to do it!
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

#7 Jesse M

    Member

  • Members
  • PipPip
  • 32 posts

Posted 22 August 2003 - 01:36 AM

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.
FRAG THE PLANET
Ed Helms: Alcohol causes problems and guns solve problems. I don't see why you can't have guns in bars.
Other guy: That's a stupid idea.
Ed Helms: Yeah, if your a pussy.

#8 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 22 August 2003 - 05:32 AM

its still a very useful feature.. very cheap to support, so what?
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#9 SYS49152

    Member

  • Members
  • PipPip
  • 57 posts

Posted 29 December 2004 - 10:19 AM

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

#10 Dia

    DevMaster Staff

  • Administrators
  • 1120 posts

Posted 29 December 2004 - 07:05 PM

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.

#11 SYS49152

    Member

  • Members
  • PipPip
  • 57 posts

Posted 30 December 2004 - 12:30 PM

nice link. thank you.

- Andy

#12 ahxian125

    New Member

  • Members
  • Pip
  • 1 posts

Posted 19 September 2005 - 01:33 PM

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

#13 Ed Mack

    Senior Member

  • Members
  • PipPipPipPip
  • 1239 posts

Posted 19 September 2005 - 04:09 PM

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

#14 Fragztor

    New Member

  • Members
  • Pip
  • 1 posts

Posted 22 September 2007 - 02:07 PM

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?

#15 Reedbeta

    DevMaster Staff

  • Administrators
  • 5306 posts
  • LocationBellevue, WA

Posted 22 September 2007 - 04:12 PM

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.)
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users