SFML community forums

Help => Graphics => Topic started by: achpile on October 24, 2017, 10:30:38 am

Title: sf::Text and Outline
Post by: achpile on October 24, 2017, 10:30:38 am
Hello  :) Is there a way to make outline only outer space with text? As you can see it works fine with shapes, but text outlined inside and outside.

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main() {
        sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
        sf::Event event;
        sf::Font font;
        sf::Text text;
        sf::RectangleShape shape;

        font.loadFromFile("font.ttf");

        text.setFont(font);
        text.setString("HELLO");
        text.setCharacterSize(200);
        text.setFillColor(sf::Color(255,0,0,128));
        text.setOutlineColor(sf::Color(0,0,0,128));
        text.setOutlineThickness(5);

        shape.setSize(sf::Vector2f(100,100));
        shape.setPosition(100, 300);
        shape.setFillColor(sf::Color(255,0,0,128));
        shape.setOutlineColor(sf::Color(0,0,0,128));
        shape.setOutlineThickness(5);

        while (window.isOpen()) {
                while (window.pollEvent(event)) if (event.type == sf::Event::Closed) window.close();

                window.clear(sf::Color::White);
                window.draw(text);
                window.draw(shape);
                window.display();
        }

        return 0;
}
 

Title: Re: sf::Text and Outline
Post by: Hapax on October 24, 2017, 03:00:24 pm
The solid part of text is the actual body of the object so any part not in the area of this body is considered outside; this includes holes, which are also not a part of the text body.

I'm curious to know why you don't want holes to be lined as well.
Title: Re: sf::Text and Outline
Post by: achpile on October 24, 2017, 03:03:16 pm
The solid part of text is the actual body of the object so any part not in the area of this body is considered outside; this includes holes, which are also not a part of the text body.

I'm curious to know why you don't want holes to be lined as well.

I was talking not about holes. Grey outline is what i need. But dark red - is blending product of red text and inside part of grey outline. Look, the color and outline color have alpha 128 (0.5f).
Title: Re: sf::Text and Outline
Post by: Hapax on October 24, 2017, 05:53:15 pm
Oh, I think I see. The text's outlines are centred on the edge rather than only extruding inwards/outwards (as I would think that it should)?
Title: Re: sf::Text and Outline
Post by: achpile on October 24, 2017, 08:22:13 pm
Oh, I think I see. The text's outlines are centred on the edge rather than only extruding inwards/outwards (as I would think that it should)?

Yes :) I made a fading "Level <N>" text with outline in my project and it looks a bit ugly because of it.
I know i can render it to texture with alpha=255 and make a sprite fading instead of text, but it's a bug anyway, i guess.
Title: Re: sf::Text and Outline
Post by: Hapax on October 24, 2017, 09:51:56 pm
Indeed that a semi-transparent text and outline would then show half over the text and half in the space.

If the property is called "outline" is should be outwards from the edge (or inwards if negative) as with the shapes.

A line that is both in and out - drawing over and centring on the edge - should be named elsewise, such as edge, edging or edgeline.

I would consider this a bug too.
Title: Re: sf::Text and Outline
Post by: Laurent on October 24, 2017, 10:05:08 pm
Have you tried with other fonts (standard ones like "Arial"), to make sure that it was not an issue with this specific font?
Title: Re: sf::Text and Outline
Post by: achpile on October 24, 2017, 11:31:51 pm
Have you tried with other fonts (standard ones like "Arial"), to make sure that it was not an issue with this specific font?

Yep, same with all fonts i've tried
Title: Re: sf::Text and Outline
Post by: Hapax on October 28, 2017, 04:58:09 pm
I've attached a (cropped) screenshot using the example code above with arial.
Title: Re: sf::Text and Outline
Post by: achpile on October 28, 2017, 05:10:45 pm
I've attached a (cropped) screenshot using the example code above with arial.

btw, negative thickness gives even more incorrect result
Title: Re: sf::Text and Outline
Post by: Hapax on October 28, 2017, 05:23:00 pm
Wow! You're right; that's absolutely terrible! :o

It's also the wrong colour; the overlapping outlines are different final colours on the shape and the text.
The text outline overlapping colour resulted in: (191, 63, 63)
Whereas the shape outline overlapping colour resulted in: (127, 63, 63)

Again, I've attached the Arial result :P
Title: Re: sf::Text and Outline
Post by: achpile on October 28, 2017, 05:40:06 pm
Wow! You're right; that's absolutely terrible! :o

It's also the wrong colour; the overlapping outlines are different final colours on the shape and the text.
The text outline overlapping colour resulted in: (191, 63, 63)
Whereas the shape outline overlapping colour resulted in: (127, 63, 63)

Again, I've attached the Arial result :P

Different colors probably caused by different drawing order. White -> Grey -> Red and White -> Red -> Grey.
Title: Re: sf::Text and Outline
Post by: Hapax on October 29, 2017, 12:19:16 am
You're probably right. The text outline likely to be a 'thick stroke' covered with the solid part of the text.
Title: Re: sf::Text and Outline
Post by: achpile on October 30, 2017, 07:03:45 am
Should I open new issue on GitHub?
Title: Re: sf::Text and Outline
Post by: Laurent on October 30, 2017, 07:58:21 am
Quote
Should I open new issue on GitHub?
Yes :)