SFML community forums

General => Feature requests => Topic started by: ZeroZ30o on November 01, 2016, 07:04:30 pm

Title: Add .setSmooth() for text
Post by: ZeroZ30o 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
Title: Re: Add .setSmooth() for text
Post by: Laurent 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?
Title: Re: Add .setSmooth() for text
Post by: ZeroZ30o 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
Title: Re: Add .setSmooth() for text
Post by: Laurent 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.
Title: Re: Add .setSmooth() for text
Post by: jokoon on December 07, 2018, 12:00:28 pm
(https://i.imgur.com/fUPzgPD.png?1)

I'm having a similar issue, I'm zooming using a sf::View, is it possible to have font textures not smoothed?
Title: Re: Add .setSmooth() for text
Post by: ZeroZ30o 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.
Title: Re: Add .setSmooth() for text
Post by: Jonny on August 12, 2020, 08:44:37 pm
Have created a pull request for this: https://github.com/SFML/SFML/pull/1690
Title: Re: Add .setSmooth() for text
Post by: eXpl0it3r on September 20, 2020, 07:18:25 pm
The pull request (https://github.com/SFML/SFML/pull/1690) was just merged, you can find builds of the master branch here (https://artifacts.sfml-dev.org/by-branch/master/).