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

Author Topic: Ability to turn off font antialiasing when rendering glyphs  (Read 7563 times)

0 Members and 1 Guest are viewing this topic.

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
I'm requesting the ability to change the rendering mode when loading font glyphs to a texture.
For pixel-based games (i.e. pixellated, "vintage looking", etc.)
As antialiased fonts look bad where everything else is pixelated.

With this parameter, the font's image smoothness should also be disabled (SetSmooth(false))

(this will solve the issue for this other guy in the forum)

"Where to change it":
src\SFML\Graphics\FontLoader.cpp @ 213
Code: [Select]
FT_Glyph_To_Bitmap(&Glyph, FT_RENDER_MODE_NORMAL, 0, 1);

Quote
FT_RENDER_MODE_NORMAL   

This is the default render mode; it corresponds to 8-bit anti-aliased bitmaps.

FT_RENDER_MODE_MONO   

This mode corresponds to 1-bit bitmaps (with 2 levels of opacity).


Example!



Thanks
-Martín

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Ability to turn off font antialiasing when rendering glyphs
« Reply #1 on: June 13, 2009, 12:12:33 pm »
I'll look into that, but it's low priority so after SFML 2.0.
Laurent Gomila - SFML developer

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Ability to turn off font antialiasing when rendering glyphs
« Reply #2 on: June 13, 2009, 12:20:53 pm »
But it's really really really reaaaaally easy to implement.

The only thing to "define" is the interface, as this should be passed to the loading functions (LoadFromFile, LoadFromMemory)

Define that and I can do it (respecting your coding notations)

maybe an extra optional parameter?

like
Code: [Select]
enum FontAntiAliasing {
    AntiAliased,                   //default
    NotAntiAliased
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Ability to turn off font antialiasing when rendering glyphs
« Reply #3 on: June 13, 2009, 12:34:55 pm »
Quote
But it's really really really reaaaaally easy to implement.

So as many other features. Most of the features to implement in the roadmap would actually take only a few minutes / hours to be done.

I actually spend most of my time thinking about how to add them properly to the public API, rather than implementing them. I don't really like rushing to implement a new feature without making absolutely sure that it's consistent with the rest of the API. Sorry if it's frustrating (I can understand it), but that's how I work ;)
Laurent Gomila - SFML developer

SkyGriffin

  • Newbie
  • *
  • Posts: 2
    • View Profile
Ability to turn off font antialiasing when rendering glyphs
« Reply #4 on: December 31, 2009, 03:24:55 pm »
I wanted to see how it looks without antialiasing so I tried changing:
      Error = FT_Load_Char(FontFace, Charset, FT_LOAD_TARGET_NORMAL);

with:
      Error = FT_Load_Char(FontFace, Charset, FT_LOAD_TARGET_MONO);

and:
      FT_Glyph_To_Bitmap(&Glyph,FT_RENDER_MODE_NORMAL, 0, 1);

with:
      FT_Glyph_To_Bitmap(&Glyph,FT_RENDER_MODE_MONO, 0, 1);

But it doesn't work. All I get is a pixel mess where the non-antialiased text should be. Any idea why? Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Ability to turn off font antialiasing when rendering glyphs
« Reply #5 on: December 31, 2009, 03:28:51 pm »
In MONO mode, a pixel is packed in a single bit instead of a byte.

The formula becomes:
Code: [Select]
dest[index] = ((src[x / 8]) & (1 << (7 - (x % 8)))) ? 255 : 0;

(if you don't see where this line of code should go, tell me which version of SFML you use)
Laurent Gomila - SFML developer