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.


Messages - Trilaterus

Pages: [1]
1
There's no such thing as a "transparent" color, sf::Color::Transparent is just a short hand for black with an alpha value of zero...

Ah I see what you mean, I remember rendering a Window using clear(Colour::Transparent) and it came out with just a black background. I'm not sure then if the issue with the glyphs being cropped is part of this or should be another issue? In any case let me try to explain it again in a little more detail.

Using the code example from the first post, if we render the Text to the RenderTexture using BlendNone:

renTex.draw(text, sf::BlendNone);

We have a rendering problem with fonts that are italic-like or calligraphic (sorry not tested more fonts and away from code atm). In the screenshot I had before the T gets cut off by the A in TALL, and the l crops the previous l in small.

My previous thought was that using BlendNone was removing the alpha component, so as each glyphs texture is drawn (from left to right) it draws white pixels over the previous text. Similar to just drawing two opaque boxes over each other.



(Tried to highlight the issue better but I've done it very rushed in paint so apologies!)

2
That does remind me that setting the blend state to none kind of worked, although it would clip with the other glyphs and I thought it would also have jagged edges (but apparently it's fine):



In this example I changed the way the Text was drawn to the RenderTexture by adding the sf::BlendNone to the draw function. I also upped the character size to 70 and changed the font colour to red to better highlight this other glyph cropping issue. It may be related to this issue or might be the intended functionality (since doing no blending means each letter is drawn over each other without transparency [I guess]).

I'm not exactly sure how to check if a glyph sheet contains a full-range alpha, although I copied the arial.ttf font from my systems font folder into the project and got a similar result to the original font (with the outline).

3
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]
anything