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

Author Topic: Suggestion for displaying text  (Read 5415 times)

0 Members and 1 Guest are viewing this topic.

Sythical

  • Newbie
  • *
  • Posts: 9
    • View Profile
Suggestion for displaying text
« on: June 19, 2013, 07:07:17 pm »
Hello, in the game I'm making I need to display small text (around size 10) on the screen. The problem I'm having is that the text displayed by SFML is a bit blurry. I've searched the forums and from what I can tell, there is no easy solution available so I was wondering how do people get around this issue. Are there any other methods to display text in the SFML window?

Thank you

Polyfructol

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Suggestion for displaying text
« Reply #1 on: June 19, 2013, 08:44:22 pm »
You're right, it's even an open issue: https://github.com/SFML/SFML/issues/254
For now, a solution is to recompile SFML with a slight change in Font.cpp, replacing FT_RENDER_MODE_NORMAL by FT_RENDER_MODE_MONO.

But you can almost totally avoid the "smoothing" effect if you take a font that was designed with the size you want (10px for your case). Then you can apply a scale multiplier (power of two for the best result) on the sf::Text in order to fit the size you really want.

I made some tests with 2 differents fonts:

http://www.dafont.com/commodore-64-pixelized.font?text=commodore+pixelized
font=Commodore Pixelized v1.2.ttf; characterSize=10; FT_RENDER_MODE_MONO


font=Commodore Pixelized v1.2.ttf; characterSize=10; FT_RENDER_MODE_NORMAL


font=Commodore Pixelized v1.2.ttf; characterSize=11; FT_RENDER_MODE_MONO


font=Commodore Pixelized v1.2.ttf; characterSize=11; FT_RENDER_MODE_NORMAL


http://www.dafont.com/grand9k-pixel.font
font=Grand9K Pixel.ttf; characterSize=8; FT_RENDER_MODE_MONO


font=Grand9K Pixel.ttf; characterSize=8; FT_RENDER_MODE_NORMAL


font=Grand9K Pixel.ttf; characterSize=9; FT_RENDER_MODE_MONO


font=Grand9K Pixel.ttf; characterSize=9; FT_RENDER_MODE_NORMAL


So, no smoothing effect if you use characterSize=8 for Grand9K and characterSize=10 for Commodore 64  ;D.

Hope it helps!
« Last Edit: June 19, 2013, 08:46:51 pm by Polyfructol »

Sythical

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Suggestion for displaying text
« Reply #2 on: June 19, 2013, 09:18:52 pm »
@Polyfructol
Thank you, your response is very helpful. I tried the fonts you suggested and the text is pretty crisp now so I'll use them. An interesting thing I noticed is that the text is much clearer when I use Arial size 32 and scale it by half instead of just using Arial size 16.

I'll have a look at the Font.cpp file later on, I wonder is there is anything planned for fonts in 2.1 ^^

Thank you once again :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Suggestion for displaying text
« Reply #3 on: June 19, 2013, 09:33:56 pm »
Quote
I wonder is there is anything planned for fonts in 2.1 ^^
https://github.com/SFML/SFML/issues?milestone=7&state=open
Laurent Gomila - SFML developer

mejak

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Suggestion for displaying text
« Reply #4 on: August 26, 2013, 02:05:48 am »
I changed the
FT_Glyph_To_Bitmap(&glyphDesc, FT_RENDER_MODE_NORMAL, 0, 1);
line to
FT_Glyph_To_Bitmap(&glyphDesc, FT_RENDER_MODE_MONO, 0, 1);
in Font.cpp, and built the libraries again with cmake, and it's still blurry. How is that possible, I can't figure out what I'm doing wrong. Is anybody kind enought to tell me what all the steps are and what I might have missed?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Suggestion for displaying text
« Reply #5 on: August 26, 2013, 07:46:52 am »
Try the latest revision (with no modification), it should already be much better.
Laurent Gomila - SFML developer

mejak

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Suggestion for displaying text
« Reply #6 on: August 26, 2013, 03:43:18 pm »
I tried the new revision, looks the same. I used the Grand9k font at size 8.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Suggestion for displaying text
« Reply #7 on: August 26, 2013, 03:45:18 pm »
Hmm ok, it seems that I need to do some tests on my side.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Suggestion for displaying text
« Reply #8 on: August 26, 2013, 07:55:18 pm »
Grand9K at size 8 renders perfectly for me with the current revision.
Laurent Gomila - SFML developer

mejak

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Suggestion for displaying text
« Reply #9 on: August 27, 2013, 07:31:56 pm »
Yes, I imagined it would, since I tried it with 2rc, 2.1 and the current source, and it was always the same, so I'm sure It's me who's not getting something.
I have a view that's 480x270 that's set to a 1440x810 window, so everything is scaled times 3.

http://imgur.com/YfTyYgR
that's my cursor sprite below the text

How come the text uses actual pixels (at least the antialised ones), and how is there still alpha with FT_RENDER_MODE_MONO?


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Suggestion for displaying text
« Reply #10 on: August 27, 2013, 07:54:22 pm »
This blur is not caused by glyph rendering, it's caused by texture filtering because of scaling.

Try this ugly hack to verify it:
const_cast<sf::Texture&>(font.getTexture(text.getCharacterSize())).setSmooth(false);
Laurent Gomila - SFML developer

mejak

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Suggestion for displaying text
« Reply #11 on: August 27, 2013, 08:08:22 pm »
Yes the ugly hack worked perfectly. I'm sorry what exactly is it, does it effect performance? Should I go on about doing it less ugly and hacky now or is it okay to use?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Suggestion for displaying text
« Reply #12 on: August 27, 2013, 08:51:34 pm »
Quote
I'm sorry what exactly is it, does it effect performance?
When a texture is scaled up, a filter is applied by the graphics card to deduce the extra pixels and fill the space. SFML supports two filters: nearest point (texture.setSmooth(false)) or linear filter (texture.setSmooth(true)). It doesn't impact performances at all.

Quote
Should I go on about doing it less ugly and hacky now or is it okay to use?
If you don't care modifying SFML, at the end of Font.cpp remove the call to texture.setSmooth(true).
If you don't want to modify SFML, using this ugly hack is the only option. It is ugly but it should be safe.
Laurent Gomila - SFML developer

mejak

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Suggestion for displaying text
« Reply #13 on: August 27, 2013, 09:18:11 pm »
Thank you very much, you were incredibly helpful. Keep up the amazing work.

 

anything