Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Raizor on May 30, 2011

Title: [C++] The best way to handle vsync for an OpenGL demo?
Post by: Raizor on May 30, 2011
Does anyone have any tips or suggestions on the best way to handle vsync issues in an OpenGL demo/intro?  It seems that if the user has their card set to automatic/application controlled, the demo may race along far too fast.  At the moment I've got some crude frame timing in place that blocks if a frame is rendered too quickly. I just wonder if there's a more elegant solution.

Any advice would be greatly appreciated.
Title: Re: [C++] The best way to handle vsync for an OpenGL demo?
Post by: padman on May 30, 2011
Maybe you should have a look at this for a start: http://www.dbfinteractive.com/forum/index.php?topic=4118.0 (http://www.dbfinteractive.com/forum/index.php?topic=4118.0) It's C(++), it's OpenGL and it's about timing.  ;)
Title: Re: [C++] The best way to handle vsync for an OpenGL demo?
Post by: Raizor on May 30, 2011
Thanks Padman!
Title: Re: [C++] The best way to handle vsync for an OpenGL demo?
Post by: padman on May 30, 2011
No prob.
Title: Re: [C++] The best way to handle vsync for an OpenGL demo?
Post by: TinDragon on May 30, 2011
I certainly rcommend using timing as even if you turn vsync on gfx drivers can override it.

Here's a function I made in C to turn vsync on or off, probably better ways to do it but it code from a good few years ago and seems to work.

Code: [Select]
/*------------------------------------------------------------------------
' NAME : SwitchVsync
' PURPOSE : This function Sets vsync on off
' INPUTS : true or false
'------------------------------------------------------------------------*/
void SwitchVsync(bool sync)
{
BOOL (APIENTRY *wglSwapIntervalEXT)(int);
wglSwapIntervalEXT=( BOOL (APIENTRY*)(int) )wglGetProcAddress("wglSwapIntervalEXT");
if (sync=true)
{
wglSwapIntervalEXT(1);
}
else
{
wglSwapIntervalEXT(0);
}
}

One quick note, you need to have created the opengl context for this to work, so once you have your opengl window opened then call this function with true or false.
Title: Re: [C++] The best way to handle vsync for an OpenGL demo?
Post by: Raizor on May 30, 2011
Thanks TinDragon. Will give that a whirl :)
Title: Re: [C++] The best way to handle vsync for an OpenGL demo?
Post by: energy on June 10, 2011
Watch here...
Very good Tutorial.
Its similar to Hitchhikrs MASM-BASEFramework

http://www.angelcode.com/dev/timefps/timefps.asp

Title: Re: [C++] The best way to handle vsync for an OpenGL demo?
Post by: Raizor on June 10, 2011
Watch here...
Very good Tutorial.
Its similar to Hitchhikrs MASM-BASEFramework

Watch where Energy?
Title: Re: [C++] The best way to handle vsync for an OpenGL demo?
Post by: energy on June 10, 2011
Sorry... edited!   :xmas:
Title: Re: [C++] The best way to handle vsync for an OpenGL demo?
Post by: Raizor on June 10, 2011
Thanks Energy. Will check that out :)