After messing with this for many hours I've managed to track down what is happening. First off, this only seems to be happening on Mac OSX (I'm on 10.9). My windows build seems to be fine. I did not test on linux yet.
Symptom: When using a RenderTexture for multiple clear/draw/display cycles within a single frame it only appears to render the final clear/draw/display but uses this texture in all of the places that the sprite using the RenderTexture.getTexture() was drawn to. This is what it looks like when trees and characters share a RenderTexture and the character is rendered last.
https://twitter.com/SiegeGames/status/486307979512123392Code: I managed to boil this down into a very simple program and reproduced the issue. Even though this should draw a red, green and blue rectangle it will instead draw 3 blue ones. One interesting thing to note that I noticed is that if you do not clear the RenderTexture then you will see were the first drawn rectangle will have the red, green and blue rectangle all overlapping. The second rectangle will only be green and blue and then the final rectangle is just blue.
void drawShape(sf::RenderWindow& window, sf::RenderTexture& texture, sf::Vector2f size, sf::Color color, sf::Vector2f position) {
texture.clear(sf::Color(0, 0, 0, 0));
sf::RectangleShape shape(size);
shape.setFillColor(color);
texture.draw(shape);
texture.display();
sf::Sprite sprite(texture.getTexture());
sprite.setPosition(position);
sprite.setTextureRect(sf::IntRect(0, 0, size.x, size.y));
window.draw(sprite);
}
int main(int argc, char** argv) {
// create the window
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
sf::RenderTexture texture;
texture.create(32, 32);
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
// clear the window with black color
window.clear(sf::Color::Black);
// draw everything here...
drawShape(window, texture, sf::Vector2f(16, 16), sf::Color(255, 0, 0), sf::Vector2f(32, 32));
drawShape(window, texture, sf::Vector2f(12, 24), sf::Color(0, 255, 0), sf::Vector2f(32, 64));
drawShape(window, texture, sf::Vector2f(24, 12), sf::Color(0, 0, 255), sf::Vector2f(32, 96));
// end the current frame
window.display();
}
return 0;
}