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

Author Topic: Font antialiasing  (Read 6196 times)

0 Members and 1 Guest are viewing this topic.

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Font antialiasing
« on: January 03, 2018, 03:28:55 pm »
Hello

I was always annoyed by how blurry the fonts were when displayed with SFML. Take the same font, display it on a browser and on a SFML window, it's not as sharp with SFML even using all the advices I could found (integer positionning, right view size...). It's especially noticeable on small font sizes.

I've found a way to correct it, by recompiling Freetype and SFML:

the change in Freetype was to uncomment FT_CONFIG_OPTION_SUBPIXEL_RENDERING in ftoption.h

then in SFML to call the function FT_Library_SetLcdFilter with FT_LCD_FILTER_LEGACY as parameter : https://www.freetype.org/freetype2/docs/reference/ft2-lcd_filtering.html

I've tried other filter values but FT_LCD_FILTER_LEGACY  was the best to my taste.

Since some people may prefer the more blurry variant, would adding a "setSharpness" function be a good idea ?

setSharpness could take a sharpness parameter for chosing between the heavy default antialias, some lighter ones or no antialising at all (it's possible, I managed to do it while messing with FreeType options)

« Last Edit: January 03, 2018, 03:30:52 pm by ratatax »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Font antialiasing
« Reply #1 on: January 03, 2018, 05:47:22 pm »
As stated at the very beginning of the documentation that you mention, this option enables a patented technique. It can't be used in SFML.
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: Font antialiasing
« Reply #2 on: January 03, 2018, 07:01:14 pm »
FreeType added its own patent free subpixel rendering algorithm in 2.8.1 released a few months ago.

https://www.freetype.org/index.html#news
http://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=410f3799b6a193e20b34c574e6f0f2be2428b1eb

They are so confident in it that it is enabled by default when ClearType is not explicitly enabled. Merely linking SFML against FreeType 2.8.1 should probably improve the quality of glyphs "for free".
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: Font antialiasing
« Reply #3 on: January 03, 2018, 07:06:04 pm »
Good news. ratatax, can you test the latest FreeType with default options and compare against what you had with ClearType enabled?
Laurent Gomila - SFML developer

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Font antialiasing
« Reply #4 on: January 04, 2018, 05:43:30 pm »
I tried the 2.8.1 with defaults and it's not better than the current SFML rendering.

However, it seems the method i explained (with FT_CONFIG_OPTION_SUBPIXEL_RENDERING and FT_LCD_FILTER_LEGACY) doesn't use ClearType, both in 2.8 which was the version I used when I wrote this post, and 2.8.1 (I didn't tried other versions). The glyphs doesn't have any colour fringes, they are purely grayscale. If ClearType was used, there would be coloured. I tried many settings and none of them were coloured in any way. So, i don't know why they talk about that. Outdated comments ? Or i misunderstood something?

Freetype is quite advanced, it's possible to have custom parameters for the antialiasing algorithm (FT_LCD_FILTER_LEGACY is just a preset), so creating some of them and making them accessible through a function would be nice. If we find what's happening with this ClearType thing i can make a pull request. Which name would be best ? setSmoothness ? setAntialiasing ?
« Last Edit: January 05, 2018, 06:25:01 pm by ratatax »

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Font antialiasing
« Reply #5 on: January 04, 2018, 06:48:09 pm »


First is FT_CONFIG_OPTION_SUBPIXEL_RENDERING + FT_LCD_FILTER_LEGACY

Second is default FreeType/SFML rendering, which looks the same as the latest FreeType with default parameters  (FT_CONFIG_OPTION_SUBPIXEL_RENDERING disabled). It may not look THAT bad on dark backgrounds, but for dark text on white bg, it's really on the blurry side.
« Last Edit: January 04, 2018, 06:54:00 pm by ratatax »