Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Help with vsync and SFML on a MAC  (Read 4625 times)

0 Members and 1 Guest are viewing this topic.

ztx_ryan

  • Newbie
  • *
  • Posts: 5
    • View Profile
Help with vsync and SFML on a MAC
« on: May 09, 2012, 03:53:53 pm »
Hi fellow SFML'ers.

I've just starting using SFML 1.6, and I have some trouble getting smooth animation when using vsync. When I print out the time passed since the last frame to the console, I get a list of VERY scattered values like this:

0.016885
0.016948
0.016119
0.0061512
0.0270939
0.0174539
0.0332918
0.0162151
0.017309
0.032944
0.016253
0.0176249
0.0328569
0.00567698
0.0282021
0.0331681
0.016572
0.0166841
0.0172169
0.0327649
0.016468
0.0166309
0.0182922
0.032073
0.016552
0.01722

And the animation looks extremely jerky. By looking at the numbers, it seems like it skips a frame pretty often (when the numbers are in the 0.03'ies, but whats the reason behind a value like 0.0061512..?) And shouldnt these numbers be VERY consistant around 0.01667 (60 FPS)?

In this example, all I do is draw a single moving square to the screen, so it is not the logic updates that are holding things back. When I disable vsync, things look alot smoother, and the values look something like this:

0.000458956
0.000432014
0.000494003
0.000482082
0.000458956
0.000513077
0.000463963
0.000466824
0.000482082
0.000499964
0.000500917
0.000490904
0.000501156

But there is lot of screen tearing, so I dont really like that solution either.

At the very top of my gameloop, I calculate the time passed since the last frame like this:

while (App.IsOpened())
{
      float FrameTime = UpdateClock.GetElapsedTime();  //UpdateClock created outside the gameloop
      UpdateClock.Reset();
...

and multiply this value into the velocity of my box, to make its logic updates independent of the specific computers' power:

       box->Update(FrameTime);
         
Then I just create a rectangle from the values stored in my box object, and draw it to the screen:
            
      sf::Shape rectangle = sf::Shape::Rectangle(box->GetX(), box->GetY(),
                                                  box->GetX() + 100, box->GetY() + 100, sf::Color::Green);
      
      App.Clear();
      
      App.Draw(rectangle);
      
      App.Display();
}

What am I doing wrong?

Has anyone here succeded in making a gameloop with smooth animation running on a Mac?

Sorry if this post seems a little confusing, I've never posted before, and just putting this down on paper turned out to be harder than i thought  :)

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Help with vsync and SFML on a MAC
« Reply #1 on: May 09, 2012, 09:37:29 pm »
Quote
I've just starting using SFML 1.6
Why not giving 2.0 RC a try ?  ;) (1.6 is not maintained since a few years.)

Quote
And shouldnt these numbers be VERY consistant around 0.01667 (60 FPS)?
Nope. It depends on too many factors to be that precise (driver implementation, OS layer, other application running, your application, ...).

You can try to set the framerate limit to 60 instead of enabling vsync.
SFML / OS X developer

ztx_ryan

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with vsync and SFML on a MAC
« Reply #2 on: May 09, 2012, 10:14:02 pm »
Thank you very much for the reply Hiura!

I havn't tried SFML 2.0, because at the time, 1.6 seemed easier to get up and running, but I will definately give it a try now! How are your experinces with 2.0 and vsync on a Mac (I'm on a MacBook with Intel HD Graphics 3000 384 MB) if you dont mind me asking?

Nice to know that the vsyncs not supposed to return consistent values when I measure the time, I have been wondering about that for a long time! I have now tried to use the SetFramerateLimit(60) method, which gives me very consistent values when I measure the time:

0.017386
0.0177701
0.0177519
0.0176961
0.017755
0.0176439
0.017705
0.017792
0.0177081
0.0175941

But still very jerky movement, and alot of tearing...

So, are my only options now? :

1. To disable vsync and let the screen render at a high enough rate to make things look smooth, but with tearing?
2. Enable vsync or frameratelimit and live with the large amount of jerkiness?
3. Move on to SFML 2.0?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Help with vsync and SFML on a MAC
« Reply #3 on: May 10, 2012, 08:45:51 am »
Quote
How are your experinces with 2.0 and vsync on a Mac
It seems to work. I have a NVidia GC so maybe something is wrong with the Intel ones.

Quote
So, are my only options now? :

1. To disable vsync and let the screen render at a high enough rate to make things look smooth, but with tearing?
2. Enable vsync or frameratelimit and live with the large amount of jerkiness?
3. Move on to SFML 2.0?
I guess trying 2 & 3 on small projects could tell you if things are better or not with 2.0.
1 is definitely not a solution.
SFML / OS X developer

ztx_ryan

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with vsync and SFML on a MAC
« Reply #4 on: May 10, 2012, 10:32:23 am »
Ok thanks a lot, I will try out 2.0 today and see how things work out.

UPDATE: I don't know, if anyone is interested, but I have now installed 2.0 and found the solution. :)

Turned out, that the vsync was messing up, whenever I was not running the program in fullscreen (creating a window that was not 1280 x 800). After adding the "sf::Style::Fullscreen" line to the creation of the window, everything is now running smooth as silk!

I now get a beautiful set of values when measuring time between frames looking something like this:

0.016462
0.016695
0.017196
0.015964
0.016488
0.017315
0.016253
0.016649
0.016575
0.016671
0.016504
0.017225
0.016182
0.016568
« Last Edit: May 11, 2012, 09:54:44 am by ztx_ryan »

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
Re: Help with vsync and SFML on a MAC
« Reply #5 on: May 10, 2012, 04:38:41 pm »
I generally get the odd 'bump' in smooth movement with Vsync (PC) in windowed mode, which clears up completely in full screen. However, this odd bumping problem in a window vanishes when switched to Windows (7) basic theme, although in the basic theme CPU always reads 25% of a 4-core.

I don't really think it has all that much to do with SFML or it would have been discoverd and corrected by now.
{much better code}