So, I've made a new example and I was surprised that the FPS is lower when it uses double buffer.
The purpose of my question is how to increase FPS by using small resolutions? Or it's impossible?
P.S. You can toggle the drawing mode by pressing "1" button:
#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{
// Settings
Vector2f windowSize(800, 600);
Vector2f resolution(100, 75);
const char* imageFile = "pic.png";
const char* fontFile = "arial.ttf";
bool useDoubleBuffer = true;
RenderWindow window;
window.create(VideoMode(windowSize.x, windowSize.y, 32), "Double buffer test", Style::Default);
RenderTexture buffer;
buffer.create(resolution.x, resolution.y);
Texture texture;
texture.loadFromFile(imageFile);
Sprite sprite(texture);
Vector2u textureSize = texture.getSize();
Vector2f textureScale(windowSize.x / textureSize.x, windowSize.y / textureSize.y);
Vector2f scale(resolution.x / windowSize.x, resolution.y / windowSize.y);
sprite.setScale(textureScale.x * scale.x, textureScale.y * scale.y);
Font font;
font.loadFromFile(fontFile);
FloatRect area(0, 0, resolution.x, resolution.y);
window.setView(View(area));
String fps;
float elapsedTime = 0.0f;
Uint32 frameCounter = 0;
Clock clock;
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
window.close();
if (event.type == Event::KeyPressed)
{
if (event.key.code == Keyboard::Escape)
window.close();
if (event.key.code == Keyboard::Num1)
useDoubleBuffer = !useDoubleBuffer;
}
}
elapsedTime += clock.restart().asSeconds();
frameCounter++;
if (elapsedTime >= 1.0f)
{
fps = std::to_string(frameCounter) + " FPS";
elapsedTime = 0.0f;
frameCounter = 0;
}
Text text(fps, font, 20);
text.setPosition(0, 0);
window.clear();
if (useDoubleBuffer)
{
buffer.clear();
buffer.draw(sprite);
buffer.display();
sf::Sprite bufferSprite(buffer.getTexture());
window.draw(bufferSprite);
}
else
{
window.draw(sprite);
}
window.draw(text);
window.display();
}
return 0;
}