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

Author Topic: Add .setSmooth() for text  (Read 16546 times)

0 Members and 1 Guest are viewing this topic.

ZeroZ30o

  • Newbie
  • *
  • Posts: 47
    • View Profile
Add .setSmooth() for text
« on: November 01, 2016, 07:04:30 pm »
I've had to use a "hack" to turn off smoothing on sf::Text (or, more specifically, sf::Font, which is where the textures are stored):


  sf::Font font;
  unsigned int characterSizeUsed = 10;
  // Load the font //
  sf::Texture& texture = const_cast<sf::Texture&>(font.getTexture(characterSizeUsed));
  texture.setSmooth(false);
 

This will fix smoothing for that font size (10).

My (preferred) fix would be to add:

sf::Font::setSmooth(bool smooth)

Another option would be to add:

sf::Font::setSmooth(unsigned int fontSize, bool smooth)

Which would smooth only certain font sizes.

Result: http://puu.sh/s33mw/8901a9d811.png
Instead of: http://puu.sh/s3014/a33fcfabe9.png
« Last Edit: November 01, 2016, 07:08:34 pm by ZeroZ30o »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Add .setSmooth() for text
« Reply #1 on: November 01, 2016, 07:47:56 pm »
It's not that easy. Glyphs are smoothed (or not) when they are created, you can't just turn it on and off. You would have to regenerate all the fon'ts textures from scratch when changing this attribute. So, my point is, it is not technically impossible but it can't be a simple Font::setSmooth(bool).

Additionally, glyphs in pixelated fonts are not supposed to be antialiased even with smoothing enabled. So I'd like to do some tests; can you provide a simple (yet complete) code that reproduces your problem, together with the font that you use?
Laurent Gomila - SFML developer

ZeroZ30o

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Add .setSmooth() for text
« Reply #2 on: November 01, 2016, 07:58:00 pm »
In that case, it would be possible to make sf::Font have a constructor that determines if smoothing is enabled or not, so that glyphs are generated correctly.

As for the font, any "pixel" font will do, such as this one: http://www.dafont.com/coders-crux.font

I mean... code is straight forward. Only details I assume you want to know would be view zoom (which is x3), and yes the text is drawn at integer positions. Between those two screenshots below the first post, the only different is the smoothing.
The issue is the same as this thread:
http://en.sfml-dev.org/forums/index.php?topic=5346.0

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Add .setSmooth() for text
« Reply #3 on: November 02, 2016, 06:34:35 am »
Looking at your posts again, I realize that this has nothing to do with how glyphs are rendered. You have a scaled text (because of the zoomed view), so I guess there's no problem if the text is not scaled? In this case you're right, the solution is to disable smoothing on the font's textures, and that can be done easily with a Font::setSmooth(bool) function.
Laurent Gomila - SFML developer

jokoon

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Add .setSmooth() for text
« Reply #4 on: December 07, 2018, 12:00:28 pm »


I'm having a similar issue, I'm zooming using a sf::View, is it possible to have font textures not smoothed?

ZeroZ30o

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Add .setSmooth() for text
« Reply #5 on: December 19, 2018, 11:28:32 pm »
If you're using fonts, do what I did above.

If it still doesn't work, try .setSmooth(false) on your RenderTexture, or whatever it is you're drawing onto.

Jonny

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • Email
Re: Add .setSmooth() for text
« Reply #6 on: August 12, 2020, 08:44:37 pm »
Have created a pull request for this: https://github.com/SFML/SFML/pull/1690

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Add .setSmooth() for text
« Reply #7 on: September 20, 2020, 07:18:25 pm »
The pull request was just merged, you can find builds of the master branch here.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/