Problem: When mCity->getEntities is > 1 or mWindow->draw() is called twice the background is just white.
What the code does: It renders a grid once into gridSprite. Then every time gridSprite is drawed, after that some circles are drawed on this.
Code:
void CityGridViewer::paintCity()
{
// 1. Render grid if necessary
static bool targetReady=false;
static sf::Texture gridTex;
static sf::Sprite gridSprite;
if (!targetReady)
{
sf::RectangleShape cell;
cell.setSize(sf::Vector2f(5,5));
cell.setOutlineColor(sf::Color::Black);
cell.setOutlineThickness(1);
City::GridCellType const*const grid = mCity->getCityGrid(); // it returns a copy of the grid
for(unsigned int x=0; x < mCity->getGridSize().x; ++x)
for(unsigned int y=0; y < mCity->getGridSize().y; ++y)
{
cell.setFillColor(sf::Color::Red);
cell.setPosition(x*scale, y*scale);
mWindow->draw(cell);
}
sf::Image gridImage = mWindow->capture();
gridTex.loadFromImage(gridImage);
gridSprite.setTexture(gridTex);
targetReady=true;
}
mWindow->draw( gridSprite );
// 2. Render entities
sf::CircleShape entity;
entity.setFillColor(sf::Color::Red);
entity.setRadius( 5 );
for (auto& e : mCity->getEntities())
{
entity.setPosition( e.position.x, e.position.y );
mWindow->draw(entity);
}
}
Does anyone has an idea?
Additionally, i'm using win7 x64 and compile with msvc11 x86. I tested it on a x64 linux with gcc4.7 x64 and it worked...