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

Author Topic: Render sf::Text in HD quality using sf::View  (Read 781 times)

0 Members and 1 Guest are viewing this topic.

RomeEmperor

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Render sf::Text in HD quality using sf::View
« on: May 14, 2022, 04:32:00 pm »
Hey!
I'm developing a co-op game and i need to draw nicknames with good quality of sf::Text. It's could be easier if the sf::View size was 1920x1080, but in my game it is 300x300.
I made a test project (https://github.com/JusticeShurup/ViewAndTextTest)

main.cpp
(click to show/hide)

result:
(click to show/hide)

As you can see the quality leaves much to be desired.

We can resize current sf::View to 1920x1080 and after resize to 300x300.
code:
(click to show/hide)
result
(click to show/hide)

Everything would be fine if not for one problem. This nickname moves, when you move camera and i don't know why.
(click to show/hide)
This happens without assigning a position to a nick. I can assign a position to a nickname, but that won't solve the other problem, which is that I won't be able to add other players' nicknames, as they will be in the wrong places.

Is it possible to display text in HD quality and still have it's actual size?


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Render sf::Text in HD quality using sf::View
« Reply #1 on: August 04, 2022, 12:11:53 am »
Sorry for the late reply :-\
Unfortunately, I can't see the images (anymore).

For text rendering there are a few important things to consider.
  • You should never scale the text object itself (i.e. zooming in or out with a view), because text should be rendered at the "native" resolution, so you get crisp text and not wrongly rasterized text
  • Use a separate view to render fix objects such as text or HUD elements, that way they won't be affected when moving the camera
  • Render text on integer positions and if you move the view, move it only integer positions. When text is put between pixel positions, the rasterizer has to decide how to render it and it might drop the "wrong" pixel, leaving your font looking crooked.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything