Author Topic: [C++] The best way to handle vsync for an OpenGL demo?  (Read 7862 times)

0 Members and 1 Guest are viewing this topic.

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
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:

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 990
  • Karma: 260
    • View Profile
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:

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Thanks Padman!
raizor

Challenge Trophies Won:

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 990
  • Karma: 260
    • View Profile
No prob.
Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
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.
« Last Edit: May 30, 2011 by TinDragon »

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Thanks TinDragon. Will give that a whirl :)
raizor

Challenge Trophies Won:

Offline energy

  • Amiga 1200
  • ****
  • Posts: 280
  • Karma: 25
    • View Profile
Watch here...
Very good Tutorial.
Its similar to Hitchhikrs MASM-BASEFramework

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

« Last Edit: June 10, 2011 by energy »
coding: jwasm,masm
hobby: www.scd2003.de

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Watch here...
Very good Tutorial.
Its similar to Hitchhikrs MASM-BASEFramework

Watch where Energy?
raizor

Challenge Trophies Won:

Offline energy

  • Amiga 1200
  • ****
  • Posts: 280
  • Karma: 25
    • View Profile
Sorry... edited!   :xmas:
coding: jwasm,masm
hobby: www.scd2003.de

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Thanks Energy. Will check that out :)
raizor

Challenge Trophies Won: