SFML community forums

Help => General => Topic started by: TheEnigmist on May 27, 2012, 05:05:59 pm

Title: setFramerateLimit doesn't work
Post by: TheEnigmist on May 27, 2012, 05:05:59 pm
I've found this problem in my SFML2 RC... i'm using this code for test it:
int main(){
        sf::RenderWindow window(sf::VideoMode(1024,768,32),"FPS: ");
        window.setFramerateLimit(500);
        //window.setVerticalSyncEnabled(true);
        while (window.isOpen()){
                window.setTitle("FPS: "+GetFrameRate());
                sf::Event events;
                while (window.pollEvent(events)){
                        if (events.type == sf::Event::KeyPressed && events.key.code == sf::Keyboard::Escape)
                                window.close();
                }

                window.clear(sf::Color::Blue);
                window.display();
        }
        return EXIT_SUCCESS;
}
With VSync ON FPS are 59~61.
With or without setFramerateLimit(500) FPS are 980~991
 
Title: Re: setFramerateLimit doesn't work
Post by: Lo-X on May 27, 2012, 05:27:37 pm
What's your GetFrameRate() function ?

I don't know if you did it, but do not enable VSync AND frameratelimit. One or the other only.
Title: Re: setFramerateLimit doesn't work
Post by: TheEnigmist on May 27, 2012, 07:15:24 pm
What's your GetFrameRate() function ?

I don't know if you did it, but do not enable VSync AND frameratelimit. One or the other only.
GetFrameRate() is a simple func to get FPS from a global sf::Clock.
I didn't enable  VSync with framelimit ON. I made this 2 tests one with VSync ON and limit OFF one with VSync OFF and limit ON. But limit doesn't work :S
Title: Re: setFramerateLimit doesn't work
Post by: Hiura on May 28, 2012, 10:20:43 am
what happens when you use a lower value than 500, say 100 ?
Title: Re: setFramerateLimit doesn't work
Post by: TheEnigmist on May 28, 2012, 07:51:16 pm
With 100 FPS are 110~112
With 200 FPS are 250
With 250 FPS are 333
With 350 FPS are 500
I used the FPS function and Playclaw to see if was my bad code, but Playclaw gives me the same FPS value...

Hope laurent come here and explain why i get these values!
Title: Re: setFramerateLimit doesn't work
Post by: Perde on May 28, 2012, 07:58:48 pm
I just tried this and it seems to happen to me as well. While vSynch works as intended, I get similar values as TheEnigmist in his last post.

Downloaded 2.0 RC something like 2-3 days ago and use all the libs as they are in the archive.

#include <SFML/Graphics.hpp>
#include <sstream>

int main()
{
    sf::RenderWindow window(sf::VideoMode(300, 200), "fps");
    window.setFramerateLimit(500);
    sf::Text fps;
    sf::Clock clock;

    std::stringstream fpsstream;

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        fpsstream.str("");
        fpsstream << 1.f/clock.getElapsedTime().asSeconds();
        fps.setString(fpsstream.str());
        clock.restart();

        window.clear();
        window.draw(fps);
        window.display();
    }

    return 0;
}
Title: Re: setFramerateLimit doesn't work
Post by: Laurent on May 28, 2012, 08:55:24 pm
setFramerateLimit is implemented with sf::sleep. The resolution of sf::sleep depends on the OS, and can be very high (like 10 or 15 ms). So you shouldn't expect setFramerateLimit to be accurate, or to work at all with very high framerates.
Title: Re: setFramerateLimit doesn't work
Post by: TheEnigmist on May 28, 2012, 09:28:04 pm
setFramerateLimit is implemented with sf::sleep. The resolution of sf::sleep depends on the OS, and can be very high (like 10 or 15 ms). So you shouldn't expect setFramerateLimit to be accurate, or to work at all with very high framerates.
Ah ok! Thx for reply!