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

Author Topic: sf::Text and Outline  (Read 11429 times)

0 Members and 1 Guest are viewing this topic.

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
sf::Text and Outline
« 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;
}
 


Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Text and Outline
« Reply #1 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: sf::Text and Outline
« Reply #2 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).

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Text and Outline
« Reply #3 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)?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: sf::Text and Outline
« Reply #4 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Text and Outline
« Reply #5 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Text and Outline
« Reply #6 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?
Laurent Gomila - SFML developer

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: sf::Text and Outline
« Reply #7 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

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Text and Outline
« Reply #8 on: October 28, 2017, 04:58:09 pm »
I've attached a (cropped) screenshot using the example code above with arial.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: sf::Text and Outline
« Reply #9 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

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Text and Outline
« Reply #10 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
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: sf::Text and Outline
« Reply #11 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Text and Outline
« Reply #12 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: sf::Text and Outline
« Reply #13 on: October 30, 2017, 07:03:45 am »
Should I open new issue on GitHub?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Text and Outline
« Reply #14 on: October 30, 2017, 07:58:21 am »
Quote
Should I open new issue on GitHub?
Yes :)
Laurent Gomila - SFML developer