Hi there,
I'm running a very basic SFML app, with two cases. One where I display a sprite, one where I do not.
Here is the FPS between thoses cases:
- Without displaying a sprite: 350 FPS
- When displaying a sprite: 230 FPS
Here are the code sample:
sf::RectangleShape background_;
background_.setSize(sf::Vector2f(1900, 1000));
background_.setFillColor(sf::Color(235, 235, 235));
background_.setOutlineColor(sf::Color::Black);
background_.setOutlineThickness(1);
background_.setPosition(20, 20);
sf::RenderWindow window(sf::VideoMode(1920, 1080, 32), "Title");
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
// Close window : exit
if (event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
window.close();
}
}
window.clear(sf::Color(150, 150, 150));
// Upon uncommenting this line, I lose about 120 FPS
//window.draw(background_);
window.display();
}
Of course getting from 350 FPS to 230 is acceptable, it still is a high value, but the problem is that when I try to display several hundred of sprites (just sf::Shape, nothing fancy), I get below 25 FPS.
Any idea about what I am doing wrong ?
FPS is non-linear, thus it's hard to make a judgment based on some drop in FPS, but SFML should be able to handle a few thousand sprites/shapes on a more or less modern GPU.
That was exactly my thought.
I'm talking about something like 600 sprites. But the FPS drops doesn't seem to be related to the number of sprites, but to their size.
I just tried something else:
sf::RectangleShape background_;
background_.setSize(sf::Vector2f(1900, 1000));
background_.setFillColor(sf::Color(235, 235, 235));
background_.setOutlineColor(sf::Color::Black);
background_.setOutlineThickness(1);
background_.setPosition(20, 20);
sf::RenderWindow window(sf::VideoMode(1920, 1080, 32), "Title");
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
// Close window : exit
if (event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
window.close();
}
}
window.clear(sf::Color(150, 150, 150));
window.draw(background_);
window.draw(background_);
window.draw(background_);
window.draw(background_);
window.draw(background_);
window.draw(background_);
window.draw(background_);
window.draw(background_);
window.draw(background_);
window.draw(background_);
window.display();
}
That's only 10 sprites, shouldn't be a problem right? and yet the FPS is down to 55 with that code (the FPS is given by FRAPS by the way).
The GPU is Intel(R) HD Graphics 4000.