SFML community forums

Help => Graphics => Topic started by: Dominator on July 08, 2009, 04:44:22 pm

Title: SetFramerateLimit problem
Post by: Dominator on July 08, 2009, 04:44:22 pm
Hi!
I recently found out about SFML, so I wanted to try it, but I already have a problem with my first test program.

I'm programming in C# using the .NET bindings.
The problem is, that the framerate limit doesn't behave as intended.

I'm trying to set the limit to 60 fps, but when I run the program, the frame rate stays only at 32 fps. But when I move another window over the SFML window, the framerate strangely rises up to 64 fps.

If I disable the limit and enable vertical sync, it perfectly stays at 60 fps, but I don't want to use vertical sync since it varies on different computers.

What I already did, was using SFML 1.5, SFML SVN and even SFML2 SVN in Windows with Visual Studio 2008 and in Ubuntu with monodevelop, but always with the same behavior.

I'm just using this simple code:
Code: [Select]

using System;
using SFML.Graphics;
using SFML.Window;

namespace SFML_Test
{
  class Program
  {
    static void App_Closed(object sender, EventArgs e)
    {
      ((RenderWindow)sender).Close();
    }

    static void Main(string[] args)
    {

      RenderWindow App = new RenderWindow(new VideoMode(640, 480, 32), "SFML_Test");
      App.Closed += new EventHandler(App_Closed);

      App.SetFramerateLimit(60);

      while (App.IsOpened())
      {      
        App.DispatchEvents();
        App.Display();
      }
    }
  }
}


I would really appreciate any ideas that could solve this problem, because I'd like to use SFML in the future instead of SDL for platform independent developing.
Title: SetFramerateLimit problem
Post by: Laurent on July 08, 2009, 05:42:28 pm
It works fine for me, the framerate is steady at 60 with your example.

How do you measure the framerate? What is your graphics card? Is your driver up-to-date?
Title: SetFramerateLimit problem
Post by: Dominator on July 08, 2009, 05:48:21 pm
I measured it first with 1 / App.GetFrameTime(), and then to make sure with fraps, but both show the same fps.

I've got a GF 8800 GTX with driver version 185.85 - vsync is set to app-controlled.
I don't think that the driver is the problem, since it behaves the same way in Ubuntu.
Title: SetFramerateLimit problem
Post by: Laurent on July 08, 2009, 05:53:51 pm
Did you try on Windows Vista or XP?
Title: SetFramerateLimit problem
Post by: Dominator on July 08, 2009, 06:07:57 pm
Windows XP SP 3.

Edit: Installed the latest driver now, but nothing changed.

Edit2: On a different computer with XP SP 3 and a Radeon X1950 it runs with 64 fps.

Where do the 32/64 frames come from, when I set it to exactly 60?
Title: SetFramerateLimit problem
Post by: Daazku on July 08, 2009, 07:42:43 pm
Quote from: "Dominator"
Windows XP SP 3.

Edit: Installed the latest driver now, but nothing changed.

Edit2: On a different computer with XP SP 3 and a Radeon X1950 it runs with 64 fps.

Where do the 32/64 frames come from, when I set it to exactly 60?


It will be MAXED to ~60fps. It can be lesser.
Title: SetFramerateLimit problem
Post by: Dominator on July 08, 2009, 07:49:01 pm
Quote from: "Daazku"
It will be MAXED to ~60fps. It can be lesser.


Yes, but 32 fps is far too little when setting the limit to 60.
I get about 7500 fps without the limit.
Title: SetFramerateLimit problem
Post by: Astrof on July 08, 2009, 08:03:15 pm
I did a simple test and I got my framerate ~62 using SetFramerateLimit.  With VerticalSync enabled I get from 59-61.
Title: SetFramerateLimit problem
Post by: drpitch on July 08, 2009, 10:26:19 pm
Are you sure you don't have vertical sync enabled??
That leap from 60 to 30 fps is a bit suspect...
Title: SetFramerateLimit problem
Post by: Dominator on July 09, 2009, 12:29:37 am
Quote from: "Astrof"
I did a simple test and I got my framerate ~62 using SetFramerateLimit. With VerticalSync enabled I get from 59-61.


Sorry, but posting that it works for you doesn't help me at all.
I already know that it should work, but it simply doesn't for me.

Quote from: "drpitch"
Are you sure you don't have vertical sync enabled??
That leap from 60 to 30 fps is a bit suspect...


Yes I'm sure, since I get ~60 fps when enabled and exactly 32 fps when disabled.
Title: SetFramerateLimit problem
Post by: Nkognito on July 09, 2009, 02:35:33 am
Aren't you doing some huge thing in the main loop (like loading image/music every time or recreating the window), how percent is you app using from the processor ?
Title: SetFramerateLimit problem
Post by: Laurent on July 09, 2009, 07:57:22 am
What if you try different values for the framerate limit?
Title: SetFramerateLimit problem
Post by: Dominator on July 09, 2009, 12:50:39 pm
Quote from: "Nkognito"
Aren't you doing some huge thing in the main loop (like loading image/music every time or recreating the window), how percent is you app using from the processor ?


See my first post for the code I'm using.
The loop only contains App.DispatchEvents() and App.Display().

Quote from: "Laurent"
What if you try different values for the framerate limit?


Did some tests now:

<22 = fps stay around limit
22-31 = exactly 21 fps
32-61 = exactly 32 fps
62-700 = exactly 64 fps
>700 = unstable jumping between 65 and ~4000 fps
Title: SetFramerateLimit problem
Post by: Laurent on July 09, 2009, 02:02:39 pm
Very weird. You should try a sample compiled with the C++ version of SFML, just to make sure that this issue is not related to the C or .Net bindings.

If you can't do it directly let me know, I'll send you such a program.
Title: SetFramerateLimit problem
Post by: Dominator on July 09, 2009, 02:21:25 pm
Same problem in C++.  :(

For now I'll use a workaround.
First I'm enabling vsync and if it equals 60 fps I leave it on, else I disable it again and set the frame limit to 60.

The only problem that can occur then is when vsync doesn't equal 60 fps and the frame limit doesn't work either.
Title: SetFramerateLimit problem
Post by: Laurent on July 09, 2009, 02:28:52 pm
Did you try on different computers? It looks like it's related to your configuration.
Title: SetFramerateLimit problem
Post by: Dominator on July 09, 2009, 03:28:08 pm
It works correctly on a different computer.
Title: SetFramerateLimit problem
Post by: csiz on July 09, 2009, 04:35:22 pm
I remember I read something about frame rates and it seems like its that situation.

The monitor goes at about 60 fps so it draws the frames at 1/60 of a second. But if you delay the frames for a little more than 1/60 s than the monitor will wait for the next round of drawing to draw that frame so there will be 2/60 distance between frames, that means 30 fps.

So the monitor tries to draw something if there is nothing it will wait another 1/60 s.

And if your delay is constantly very little more than 1/60 you will get 30 fps, if its more than 2/60 you will get 20 fps (because it jumps 2 frames for every frame drawn) and so on.
Title: SetFramerateLimit problem
Post by: Laurent on July 09, 2009, 04:37:27 pm
This applies only when vertical synchronization is activated.
Title: SetFramerateLimit problem
Post by: Dominator on December 12, 2009, 01:03:12 pm
Now I have strange issues with the framelimit on a different computer.

Setting the framelimit to 60 results in 50 fps.
But when using VSync it reaches nearly exactly 60 fps.

So to get over the 50 fps, I had to set 90 fps as framelimit (which results in 100 fps), but this works only occasionally, sometimes it's capped at exactly 64 fps (like in the original issue in this thread), but most time it's 100 fps.

From what I can see, is that the factor 2 is somehow involved.

32 vs 64 fps
50 vs 100 fps
Title: SetFramerateLimit problem
Post by: drobole on December 28, 2009, 05:26:59 pm
Im having a similar problem.
I'm using Windows 7 x64, VC++ 2008 Express and latest trunc of SFML from SVN.

Running with no clamps on the frame limit and vertical sync disabled I get ~2700 FPS

Using SetFramerateLimit here is the measures I get:
Code: [Select]

FrameLimit(10) - FPS(9)
FrameLimit(20) - FPS(16)
FrameLimit(30) - FPS(21)
FrameLimit(40) - FPS(32)
FrameLimit(50) - FPS(32)
FrameLimit(60) - FPS(32) Jumps to 64 now and then
FrameLimit(70) - FPS(64)
FrameLimit(80) - FPS(64)
FrameLimit(120) - FPS(64)
FrameLimit(500) - FPS(64)
FrameLimit(700) - FPS(1800)
FrameLimit(800) - FPS(2700)
FrameLimit(> 800) - FPS(2700)


Here is how I calculate FPS:
Code: [Select]

float framerate = 1.f / window.GetFrameTime();
std::stringstream ss;
ss << "FPS: " << framerate;
mDebugInfo->SetText(ss.str());