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

Author Topic: Anti-Aliasing of Text  (Read 12186 times)

0 Members and 1 Guest are viewing this topic.

Askr

  • Newbie
  • *
  • Posts: 6
    • View Profile
Anti-Aliasing of Text
« on: July 12, 2012, 10:04:35 am »
Hey there,

I'm making a game with very simple graphics and the default anti-aliasing of the text is really unfitting.
Is there a way to render the text without any anti-aliasing at all? I've been looking through the documentary and haven't found anything.

Thanks in advance :)

Acrobat

  • Full Member
  • ***
  • Posts: 153
    • View Profile
Re: Anti-Aliasing of Text
« Reply #1 on: July 12, 2012, 10:24:06 am »
try to set x and/or y position on float coords (+= 0.375,  += 0.5)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Anti-Aliasing of Text
« Reply #2 on: July 12, 2012, 10:38:43 am »
Can you show a screenshot? Antialiasing cannot be disabled for text, but you shouldn't need to do that.
Laurent Gomila - SFML developer

mastodona7x

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Anti-Aliasing of Text
« Reply #3 on: July 12, 2012, 12:12:49 pm »
Maybe I'm missing something but why can't you just use a really simple looking font?? Plenty of free pixel-looking fonts here for instance?? http://www.dafont.com/bitmap.php, download, stick it in a /fonts/ folder in your project dir

sf::Font font;
     if (!font.loadFromFile("fonts/somesimplefont.ttf"))
         return EXIT_FAILURE;
« Last Edit: July 12, 2012, 12:22:55 pm by mastodona7x »

Askr

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Anti-Aliasing of Text
« Reply #4 on: July 12, 2012, 01:53:35 pm »
Hej,

Quote
try to set x and/or y position on float coords (+= 0.375,  += 0.5)
I tried that but it didn't really improve anything. In fact it appeared to me even more blurred.

Quote
Can you show a screenshot? Antialiasing cannot be disabled for text, but you shouldn't need to do that.
Yeah, sure. I added it as an attachement.

Quote
Maybe I'm missing something but why can't you just use a really simple looking font??
I'm using this font here: Terminalscope

[attachment deleted by admin]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Anti-Aliasing of Text
« Reply #5 on: July 12, 2012, 02:26:38 pm »
Can you try the same text but in a minimal app? This way we're sure that it's really the text itself, and not a side effect of something else in your game.
Laurent Gomila - SFML developer

Askr

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Anti-Aliasing of Text
« Reply #6 on: July 12, 2012, 03:04:24 pm »
I also added the source:

        static void Main(string[] args)
        {
            RenderWindow window = new RenderWindow(new VideoMode(640, 480), "Test");
            window.Closed += new EventHandler(OnClose);

            // Load a sprite
            Texture texture = new Texture("cute_sprite.jpg");
            Sprite sprite = new Sprite(texture);

            // create a string
            Font terminalscope = new Font("terminalscope.ttf");
            Text text = new Text("This is a test of font in front of a sprite", terminalscope);
            text.Color = new Color(0, 0, 0, 255);
       
            // run as long as the window is open
            while (window.IsOpen())
            {
                // check all triggered events since last iteration
                window.DispatchEvents();
               
                // clear screen
                window.Clear();

                // draw sprite
                window.Draw(sprite);

                // draw text
                window.Draw(text);

                // update window
                window.Display();
            }
        }

[attachment deleted by admin]
« Last Edit: July 12, 2012, 03:20:56 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Anti-Aliasing of Text
« Reply #7 on: July 12, 2012, 03:22:20 pm »
Nice, thank you :)
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Anti-Aliasing of Text
« Reply #8 on: July 12, 2012, 08:39:36 pm »
I can disable antialiasing easily, here is the result:


You can see that it's not perfect. I don't know if this can be improved easily, it would probably require sub-pixel adjustments.

[attachment deleted by admin]
Laurent Gomila - SFML developer

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Anti-Aliasing of Text
« Reply #9 on: July 13, 2012, 04:17:20 am »
I can disable antialiasing easily
Did you achieve this through modification of the SFML source or usage of the public interfaces? I don't see how the second option is even possible because of this. Font smoothing can get annoying if it is not disable-able and you have an idea of what you want to do e.g. disable blending and still have text work purely with alpha testing. Sure this might be a niche case like all the other cases you might know me for, but many features already part of the SFML interface are of exactly the same caliber (like sf::Texture::setSmooth(...) ). They are nice to have but don't really find their place except in special cases.

Because disabling font anti-aliasing actually has valid use cases e.g. when you want to apply FSAA anyway, it would be nice to have some sort of sf::Font::setSmooth( bool smooth ) or sf::Font::Font( bool smooth ) that utilizes FT_RENDER_MODE_MONO for rendering.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Anti-Aliasing of Text
« Reply #10 on: July 13, 2012, 08:04:18 am »
Yes, I meant that I changed to FT_RENDER_MODE_MONO internally.

I understand your arguments, and I more or less agree, but exposing this feature is more complicated than, for example, Texture::setSmooth, because:

1. It cannot be applied after the glyph has been loaded, so it would be an argument of the loadFromXxx functions; I could probably live with though.

2. The result is not very good, so I have to investigate other rendering options (probably sub-pixel rendering and font hinting); some of these options might not be patent-free.

I'll add an issue to the tracker so that it can be discussed further and investgated in a future version.
Laurent Gomila - SFML developer

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Re: Anti-Aliasing of Text
« Reply #11 on: July 13, 2012, 08:04:26 pm »
Even if only when loading the font (loadFrom* functions) you could add an optional parameter to customize this behaviour.

If needed to toggle between two modes, just use different sf::Font objects with the same font file but different options.

Regards

Askr

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Anti-Aliasing of Text
« Reply #12 on: July 16, 2012, 01:56:14 pm »
Quote
I can disable antialiasing easily
Sorry, but I'm unaware of how you did that. Could you please elaborate? I'm using SFML.net if that's of any importance here, btw. :(

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Anti-Aliasing of Text
« Reply #13 on: July 16, 2012, 02:20:54 pm »
Quote
Sorry, but I'm unaware of how you did that. Could you please elaborate?
I made an internal modification directly in the SFML sources. Sorry if it was not clear.

If you want to do it yourself and recompile everything, binary1248 gave a link to the source file and line that must be modified.
Laurent Gomila - SFML developer

Askr

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Anti-Aliasing of Text
« Reply #14 on: July 17, 2012, 09:57:29 am »
Ah, I see! Thanks for clarification. :)
I'll look into recompiling everything, but not right now. I'm fine for now, knowing it is possible. :)