It turns out it has to do with my environment, as Laurent said, but in a way I didn't expect: it seems that, for some reason, SFML renders windows very slowly on the my laptop (which is a more than decent computer otherwise). The following simple program should show a rotating red rectangle in a 800x600 window. The user can increase/decrease rotation speed by the up/down arrow keys, respectively:
#include <SFML/Graphics.hpp>
int main() {
int delay=1;
sf::RenderWindow window(sf::VideoMode(800,600),"Test");
sf::RectangleShape square(sf::Vector2f(100,100));
sf::Event event;
window.clear();
window.display();
square.setOrigin(50,50);square.setPosition(400,300);
square.setFillColor(sf::Color(255,0,0));
while (window.isOpen()) {
while (window.pollEvent(event)) {
if (event.type==sf::Event::KeyPressed)
switch(event.key.code) {
case sf::Keyboard::Escape:window.close();break;
case sf::Keyboard::Up:delay>0?delay--:delay;break;
case sf::Keyboard::Down:delay++;break;
default:break;
}
else if (event.type==sf::Event::Closed) window.close();
}
square.rotate(1);
window.clear();
window.draw(square);
window.display();
sf::sleep(sf::milliseconds(delay));
}
return EXIT_SUCCESS;
}
Normally, the rectangle should rotate very fast initially - so fast that you couldn't even realize it is a rectangle (on my desktop computer (with a Nvidia GPA) it looks like a circle, as the rotation speed is initially very high. Unfortunately, this is not the case on my laptop: even if I remove the line sf::sleep(sf::milliseconds(delay)); (so no delay at all between frames), it is still rotating very slowly. I can't think of any other reason than slow window rendering.
I suspect it has to do with the driver for my graphics card (an integrated Intel GPA). Note, however, that this laptop is able to run "heavy" 3D games that use OpenGL extensively, without any problem. So I am guessing something is wrong with the way SFML cooperates with OpenGL in that specific graphics card.
Attached, please find the log file from Xorg, in case it helps identifying the problem.
[attachment deleted by admin]
Unfortunately stuff like this aren't really new for some Intel drivers, even on Windows (try rendering to textures on an older Eee Pad for example...).
To force software rendering you should be able to simply set an environment variable, something like:
LIBGL_ALWAYS_SOFTWARE=1 ./your_binary
To force software rendering you should be able to simply set an environment variable, something like:LIBGL_ALWAYS_SOFTWARE=1 ./your_binary
It works, in the sense there is a significant boost in fps, together with the usual drawback of software rendering, namely glitches. Better than nothing, I guess. Thank you for the tip :)
So, if I understand well, it is impossible to switch to software rendering using SFML itself?