Any window capped at 60 FPS suddenly gets 5-10% extra CPU usage. Everything works fine uncapped/capped at 120+ no matter if it's simple rectangle or a medium-sized game prototype.
Example:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 800), "Encore");
window.setFramerateLimit(60);
sf::RectangleShape rectangle;
rectangle.setSize(sf::Vector2f(100, 100));
rectangle.setPosition(0, 0);
rectangle.setFillColor(sf::Color(100, 250, 50));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
return 0;
}
}
window.clear();
window.draw(rectangle);
window.display();
}
return 0;
}
Do you enforce VSync in your global GPU driver settings?
Yup, I did and turning it off solved the problem. Is there any way to detect that and still limit the game to 60 FPS, or would this work too:
int main()
{
sf::Vector2f resolution = { 1920, 1080 };
sf::RenderWindow window(sf::VideoMode(resolution.x, resolution.y), "ChronoTest", sf::Style::Close);
using clock = std::chrono::steady_clock;
using frameLimit = std::chrono::duration<int, std::ratio<1, 60>>;
while (window.isOpen())
{
auto frameStart = clock::now();
// Game Logic
if (clock::now() - frameStart < frameLimit(1)) std::this_thread::sleep_until(frameStart + frameLimit(1));
}
return 0;
}