Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Trilaterus

Pages: [1]
1
Graphics / Drawing Text on transparent RenderTexture leaves outline
« on: April 26, 2017, 08:47:28 pm »
In my application code I have a vector (of vectors) of sf::Text's that I render to a sf::RenderTexture. When trying to draw the RenderTexture the edges of the text are not fully transparent.

I've got a minimal code example mocked up in my main cpp file:
int main()
{
        sf::RenderWindow window(sf::VideoMode(1366, 768), "SFML works!");

        float fFrameRate = 60.f;
        window.setFramerateLimit(static_cast<unsigned int>(fFrameRate));

        sf::Font font;
        font.loadFromFile("Assets/Fonts/Lin.ttf");

        sf::Text text;
        //text.setFillColor(sf::Color::Red);
        text.setFont(font);
        text.setString("Some TALL | TEXT | some y_, small text.");
        text.setPosition(std::floor(text.getPosition().x), std::floor(text.getPosition().y));
        text.setOrigin(std::floor(text.getOrigin().x), std::floor(text.getOrigin().y));
        text.setScale(std::floor(text.getScale().x), std::floor(text.getScale().y));

        sf::RenderTexture renTex;
        renTex.create(static_cast<unsigned int>(text.getGlobalBounds().width), static_cast<unsigned int>(font.getLineSpacing(30)));
        renTex.clear(sf::Color::Transparent);
        renTex.draw(text);
        renTex.display();

        sf::Sprite sprite;
        sprite.setTexture(renTex.getTexture());
        sprite.setPosition(std::floor(sprite.getPosition().x), std::floor(sprite.getPosition().y));
        sprite.setOrigin(std::floor(sprite.getOrigin().x), std::floor(sprite.getOrigin().y));
        sprite.setScale(std::floor(sprite.getScale().x), std::floor(sprite.getScale().y));

        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(sprite);

                window.display();
        }

        return 0;
}
 



I found this post which seemed to have a similar problem with Text and RenderTexture, but clearing the RenderTexture with Color::Transparent hasn't seemed to solve the problem. In this test case I could just clear the RenderTexture with White (the same colour I'm clearing the window with) but in my application code the text will be drawn over all variety of things.

I also remember reading in all sorts of places that it's best to check that the sprites are drawn on the pixel to reduce the chance of it being rendered over two pixels and then looking odd, so a lot of this code is trying to keep the position, origin and scale on the pixel.

I'm using SFML-2.4.1 and my graphics card is an NVIDIA GeForce GTX 760.

Let me know if I'm missing any information.

Pages: [1]