hello everybody. consider this little piece of code:
#include <SFML/Graphics.hpp>
int main(){
sf::RenderTexture temp_render;
sf::Texture tex;
sf::Sprite spr;
temp_render.create(200, 200);
temp_render.clear(sf::Color::Transparent);
sf::VertexArray square;
sf::Color color_1(255, 0, 0, 255);
sf::Color color_2(255, 0, 0, 0);
square.setPrimitiveType(sf::PrimitiveType::Quads);
square.append(sf::Vertex(sf::Vector2f(0, 0), color_2));
square.append(sf::Vertex(sf::Vector2f(0, 200), color_2));
square.append(sf::Vertex(sf::Vector2f(200, 200), color_1));
square.append(sf::Vertex(sf::Vector2f(200, 0), color_1));
temp_render.draw(square);
temp_render.display();
tex = temp_render.getTexture();
spr.setTexture(tex);
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML Window");
while (window.isOpen()){
sf::Event event;
while (window.pollEvent(event)){
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::White);
window.draw(spr);
window.display();
}
return 0;
}
if you render it, you'll get:
BUT, if you change the line
window.draw(spr);
to
window.draw(square);
meaning that you'll draw the square directly to the screen, instead of drawing it to a RenderTexture and then to the screen, you'll get:
what makes me think: why this difference? I believe that when setting something to sf::Color::Transparent, it stores black pixels (as sf::Color::Transparent = sf::Color(0, 0, 0, 0)). but these pixels shouldn't be shown at all, since they're transparent, right?
as i don't know if this is expected or is a bug, i tought it would be better to ask here
thanks!