1
Graphics / Re: sf::RenderTexture not working properly
« on: April 03, 2022, 04:08:54 pm »
Hello again,
In case someone finds this in the future, I've managed to fix the lag without using sf::RenderTexture. I've read more on the SFML drawing API and it turns out the lag was not because of the data size but rather because of the high number of sf::RenderWindow::draw() calls.
What I did in my project code was a long "for" loop that sets 3 temporary sf::Vertex variables to desired coordinates and color and draw a single triangle using these vertices each iteration. This meant if there was 3000 triangles, draw() would be called 3000 times which was what caused the lag.
so the fix was to simply make a huge std::vector<sf::Vertex> and set up every single Vertex coordinate and color then pass this vector as the sf::Drawable argument in a single sf::RenderWindow::draw() call.
This still means the sf::RenderTexture is not working with float coordinates but thankfully I don't have to use it.
Thanks again everyone who answered. And thanks to SFML developers for the amazing library.
In case someone finds this in the future, I've managed to fix the lag without using sf::RenderTexture. I've read more on the SFML drawing API and it turns out the lag was not because of the data size but rather because of the high number of sf::RenderWindow::draw() calls.
What I did in my project code was a long "for" loop that sets 3 temporary sf::Vertex variables to desired coordinates and color and draw a single triangle using these vertices each iteration. This meant if there was 3000 triangles, draw() would be called 3000 times which was what caused the lag.
so the fix was to simply make a huge std::vector<sf::Vertex> and set up every single Vertex coordinate and color then pass this vector as the sf::Drawable argument in a single sf::RenderWindow::draw() call.
This still means the sf::RenderTexture is not working with float coordinates but thankfully I don't have to use it.
Thanks again everyone who answered. And thanks to SFML developers for the amazing library.