SFML community forums
Help => Graphics => Topic started 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:
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.
-
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?
-
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.
-
Did you try on Windows Vista or XP?
-
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?
-
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.
-
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.
-
I did a simple test and I got my framerate ~62 using SetFramerateLimit. With VerticalSync enabled I get from 59-61.
-
Are you sure you don't have vertical sync enabled??
That leap from 60 to 30 fps is a bit suspect...
-
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.
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.
-
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 ?
-
What if you try different values for the framerate limit?
-
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().
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
-
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.
-
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.
-
Did you try on different computers? It looks like it's related to your configuration.
-
It works correctly on a different computer.
-
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.
-
This applies only when vertical synchronization is activated.
-
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
-
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:
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:
float framerate = 1.f / window.GetFrameTime();
std::stringstream ss;
ss << "FPS: " << framerate;
mDebugInfo->SetText(ss.str());