A primitive test to see if it could handle the drawing efficiently when resized in runtime.
sf::RenderImage surface;
sf::Sprite surfaceSprite;
sf::Vector2i pos; //Store mouse position, checks if changed
sf::RenderWindow window(sf::VideoMode(800, 600));
window.SetFramerateLimit(60);
while (window.IsOpened())
{
sf::Event event;
while (window.PollEvent(event))
{
// Window closed or escape key pressed : exit
if (event.Type == sf::Event::Closed)
{
window.Close();
break;
}
}
window.Clear();
//Surface test
if (pos != sf::Mouse::GetPosition(window)) //Change if mouse moved
{
pos = sf::Mouse::GetPosition(window);
surface.Create(pos.x, pos.y); //This line
surface.Clear(sf::Color::White);
surface.Display();
}
surfaceSprite.SetImage(surface.GetImage());
window.Draw(surfaceSprite);
//Draw fps
int temp = window.GetFrameTime();
if (temp > 0)
{
char out[3];
int fps = 1000 / temp; //Some computers 1 / time works, for this pc only 1000 gives accurate amount
itoa(fps, out, 10);
sf::Text text(out);
window.Draw(text);
}
//
window.Display();
}
Reallocating an area for a surface per frame may be extreme, but achieving 17-18 of these a second is quite limiting. Just need a way to resize in a reasonable amount of time.