SFML antialiasing doesn't work properly when clearing RenderTexture with transparency

Viewed 80

I have an SFML RenderTexture that I am creating like so:

sf::ContextSettings settings;
settings.antialiasingLevel = 8;
this->texture.create(size.x, size.y, settings);

Every frame I am clearing it with transparency and drawing a RoundedRectangleShape on it:

this->texture.clear(sf::Color::Transparent);

sf::RoundedRectangleShape shape(sf::Vector2f(this->size.x, this->size.y), 15, 16);
shape.setFillColor(this->colour.sfml());

this->texture.draw(shape);

this->texture.display();

With the transparent clearing, the corners don't look as smooth as with the background colour:

enter image description here

If I clear it with the background colour using this->texture.clear(sf::Color::Black);, antialiasing works fine and the corners are smooth:

background colour clearing

1 Answers

Took me more than just a few hours, but I finally managed to crack this issue. For some odd reason, there is an issue with the BlendAlpha BlendMode where it doesn't function as expected unless the transparency is white.

That's right, the color of the transparency matters apparently. To fix your issue, you'll want to replace "sf::Color::Transparent" with "sf::Color(255, 255, 255, 0)".

Related