Hi
I recently switched to linux ( Ubuntu 18.04 )
Before when i ran the following code on my windows machine the cpu usage would stay fairly low but now when i run it on linux my cpu usage instantly goes to 100% (which makes sense since its a never ending while loop - now that i think about it)
This is my code:
#include <SFML/Window.hpp>
int main()
{
sf::Window window(sf::VideoMode(800, 600), "My window");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
}
return 0;
}
but im just curious why it didnt use 100% cpu when i ran it on my windows machine. Did i do something wrong? or is it this supposed to happen?
My theory is that on windows sfml automatically sleeps to match the screens refresh rate and for whatever reason it doesnt on linux.
Is there any way to turn this back on? i know i can decrease the cpu usage myself, by sleeping after each loop but id rather let sfml handle it if possible
I tried adding:
window.setFramerateLimit(10u);
window.setVerticalSyncEnabled(true);
but that doesn't fix it :<