• Welcome to Dark Bit Factory & Gravity.
 

[C++] The best way to handle vsync for an OpenGL demo?

Started by Raizor, May 30, 2011

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Raizor

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.
raizor

Challenge Trophies Won:

padman

Maybe you should have a look at this for a start: http://www.dbfinteractive.com/forum/index.php?topic=4118.0 It's C(++), it's OpenGL and it's about timing.  ;)
Challenge Trophies Won:

Raizor

raizor

Challenge Trophies Won:

padman

Challenge Trophies Won:

TinDragon

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.

/*------------------------------------------------------------------------
' 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.

Raizor

Thanks TinDragon. Will give that a whirl :)
raizor

Challenge Trophies Won:

energy

Watch here...
Very good Tutorial.
Its similar to Hitchhikrs MASM-BASEFramework

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

coding: jwasm,masm
hobby: www.scd2003.de

Raizor

Quote from: energy on June 10, 2011
Watch here...
Very good Tutorial.
Its similar to Hitchhikrs MASM-BASEFramework

Watch where Energy?
raizor

Challenge Trophies Won:

energy

coding: jwasm,masm
hobby: www.scd2003.de

Raizor

raizor

Challenge Trophies Won: