Thanks for your reply, Laurent.
I'm trying yo optimize fps in my game and realized my entire minimap took more than 16300 microseconds to draw with this code :
void Application::DrawMiniMap(){
sf::RectangleShape rs;
for(int i = 0; i < 100; i++) {
for(int j = 0; j < 100; j++) {
rs.setPosition(2 * i, 2 * j);
rs.setSize(sf::Vector2f(2,2));
rs.setFillColor(img.tuile[game.carte.terrainType[i][j]].GetColor());
window.draw(rs);
}
}
}
I tried this code and it only takes about 300 microseconds now, but.. it doesn't work
void Application::DrawMiniMap(){
sf::Texture tx;
tx.create(100,100);
std::vector<sf::Uint8> image(100 * 100 * 4);
for(int x = 0; x < 100; x++) {
for(int y = 0; y < 100; y++) {
image[(x + y * 100) * 4 + 0] = img.tuile[game.carte.terrainType[x][y]].GetColor().r;
image[(x + y * 100) * 4 + 1] = img.tuile[game.carte.terrainType[x][y]].GetColor().g;
image[(x + y * 100) * 4 + 2] = img.tuile[game.carte.terrainType[x][y]].GetColor().b;
image[(x + y * 100) * 4 + 3] = img.tuile[game.carte.terrainType[x][y]].GetColor().a;
}
}
// update texture:
tx.update(image.data());
sf::Sprite spt;
spt.setPosition(576,24);
spt.setTexture(tx);
window.draw(spt);
}
EDIT : I forgot to texture.create() and now it perfectly works with only ~350 microseconds, thanks a lot Laurent
EDIT 2: As my minimap is 200x200 and not 100, it actually takes 1250 microseconds to draw the minimap this way. Do you know a way to optimize even more ?