Hello,
I'm making a project that reads a big amount of small float data and I use this data to draw sort of a heat map.
Everything is working out great if I draw everything every frame straight into the sf::RenderWindow and I use a view to zoom in to my heat map and scroll around.
However if the data size is too big, drawing everything every frame as small triangles is too much and lags everything. So I decided to try to use sf::RenderTexture and render everything on it one time. And only update it if I zoom or if the data changes.
The problem is drawing things using small float data as coordinates into a sf::RenderTexture just doesn't work. But it works perfectly in a RenderWindow.
Is this intentional ? if so, is there another way to achieve what I'm trying to do ?
Here's a complete code example to show that drawing with float coordinates works on sf::RenderWindow but not on sf::RenderTexture
#include <SFML/Graphics.hpp>
//view size
#define L 6
#define H 6
//size of object to draw
#define RL 2.5
#define RH 1.5
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 800), "SFML works!");
sf::View view;
view.setSize(L,H);
view.setCenter(L/2,H/2);
window.setView(view);
sf::RenderTexture texture;
//texture.setView(view);
sf::RenderTarget& target = texture; //case 1 window , case 2 texture
texture.create(L,H);
sf::Sprite sprite;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::White);
texture.clear(sf::Color::White);
sf::RectangleShape rect(sf::Vector2f(RL/2, RH/2));
rect.setPosition(0,0);
rect.setFillColor(sf::Color::Red);
target.draw(rect);
rect.setPosition(RL/2,0);
rect.setFillColor(sf::Color::Blue);
target.draw(rect);
rect.setPosition(0,RH/2);
rect.setFillColor(sf::Color::Green);
target.draw(rect);
rect.setPosition(RL/2,RH/2);
rect.setFillColor(sf::Color::Yellow);
target.draw(rect);
sprite.setTexture(texture.getTexture());
sprite.setPosition(0,0);
//window.draw(sprite); // uncomment this line for case 2
window.display();
}
return 0;
}