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

Author Topic: setFramerateLimit doesn't work  (Read 4304 times)

0 Members and 2 Guests are viewing this topic.

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
setFramerateLimit doesn't work
« 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
 

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: setFramerateLimit doesn't work
« Reply #1 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.

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Re: setFramerateLimit doesn't work
« Reply #2 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

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: setFramerateLimit doesn't work
« Reply #3 on: May 28, 2012, 10:20:43 am »
what happens when you use a lower value than 500, say 100 ?
SFML / OS X developer

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Re: setFramerateLimit doesn't work
« Reply #4 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!

Perde

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: setFramerateLimit doesn't work
« Reply #5 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;
}
« Last Edit: May 28, 2012, 08:04:48 pm by Perde »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: setFramerateLimit doesn't work
« Reply #6 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.
Laurent Gomila - SFML developer

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Re: setFramerateLimit doesn't work
« Reply #7 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!

 

anything