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

Author Topic: Text is always blurry on low resolution games.  (Read 2442 times)

0 Members and 1 Guest are viewing this topic.

Astamor

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Text is always blurry on low resolution games.
« on: June 16, 2024, 09:58:45 am »
I've tried basically everything but the .ttf fonts are always blurry. It's pixel art game so the resolution is low, 1024x576. Unfortunately despite pixel art being most common art style for indie games there isn't a single word about rendering text on lower resolution anywhere. I've tried converting .ttf to .fnt but SFML throws an error:
Failed to load font "../resources/kanit.fnt" (failed to create the font face).
What are my options to render sharp, crisp text ? Is there a common approach to this ?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Text is always blurry on low resolution games.
« Reply #1 on: June 16, 2024, 09:54:51 pm »
The first thing to make sure is that your text co-ordinates are rounded to the nearest pixel.

Assuming your view is 1:1 with pixels (e.g. 1024x576 view for 1024x576 pixel sized), your text position and origin should both be rounded to an integer.

Note that, also, scaling text can cause it to be blurry. For larger, non-blurry text, use a larger character size instead of scaling up. If you're animating, you should likely use the larger text and scale it down instead of using a smaller text and scaling it up.

So, assuming you're now using a scale of (1,1), your view matches the actual pixel size of its viewport, and your positions and origins are all rounded values, you should now how non-blurry text.

Remember that resizing a window will not resize the view automatically so you would need to update the view when it gets resized.



In addition, I think there is an update along these lines (ability to turn off texture smoothing for text) too but I'm not sure if that has been completed.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Text is always blurry on low resolution games.
« Reply #2 on: June 17, 2024, 09:51:17 am »
As Hapax said, text should never be scaled, instead you should pick a different font size.

If you use a view for the game, you may want to use a second view just for the text, to render that without scaling.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything