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

Author Topic: [SOLVED] All fonts I try to use are blurred randomly.  (Read 2045 times)

0 Members and 1 Guest are viewing this topic.

SuperNova

  • Newbie
  • *
  • Posts: 3
    • View Profile
[SOLVED] All fonts I try to use are blurred randomly.
« on: July 26, 2016, 01:22:25 pm »
I've been struggling with this for a whole day now and I decided to ask it again, seeing as this is (used to be?) a common problem.

My sf::Font is always blurred unless they are really big (Bigger then 20px or 32px for some).



DialogueFont = new sf::Font;
        if (!DialogueFont->loadFromFile(Folders::ROOT_FOLDER + Folders::DIALOGUE_FOLDER + "Ace-Attorney.ttf"))
        {
                std::cout << "Failed to load Dialogue font!" << std::endl;
        }

        TextRenderer = new sf::Text();
        TextRenderer->setFont(*DialogueFont);
        TextRenderer->setColor(sf::Color::White);

----more code here----

        TextRenderer->setString(pCurrentUnit->getCHAR()->getNAME());
        TextRenderer->setCharacterSize(16);
        TextSanitizer::CenterOrigin(TextRenderer);
        TextRenderer->setPosition(108, 34);
        pWindow->draw(*TextRenderer);

        TextRenderer->setString(pCurrentUnit->getCLASS()->GetNAME());
        TextSanitizer::CenterOrigin(TextRenderer);
        TextRenderer->setPosition(242, 34);
        pWindow->draw(*TextRenderer);
 

It's always random, some texts come out crisp and other ones unreadable. I've read about Issue #228 but that's 4 years ago, wich said it got fixed in SFML 2, wich I use. The rest all say that the position should be rounded to ints, but mine already are ints.

I tried about 15 fonts and none will show normal consistently at 16px. Not even Arial works.

void TextSanitizer::CenterOrigin(sf::Text* _pText)
{
        sf::FloatRect textRect = _pText->getLocalBounds();
        _pText->setOrigin(textRect.left + textRect.width / 2.0f, textRect.top + textRect.height / 2.0f);
}
 
If you wanna see the centering code.
« Last Edit: July 26, 2016, 01:51:49 pm by SuperNova »

Jonny

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • Email
Re: All fonts I try to use are blurred randomly.
« Reply #1 on: July 26, 2016, 01:36:08 pm »
Although your position is rounded to ints, your origin isn't, which will cause the same issue. Try rounding that too

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: All fonts I try to use are blurred randomly.
« Reply #2 on: July 26, 2016, 01:36:36 pm »
Quote
The rest all say that the position should be rounded to ints, but mine already are ints.
If the text width is odd, the position will never be integer because you center the origin. To be perfectly safe you should also round the origin.

The position is only one of many things that can lead to a fractional position, see the documentation for more details:
http://www.sfml-dev.org/documentation/2.3.2/classsf_1_1Transformable.php#details
Laurent Gomila - SFML developer

SuperNova

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: All fonts I try to use are blurred randomly.
« Reply #3 on: July 26, 2016, 01:51:32 pm »
Very good.

Casting the origin to an int fixed it.

sf::FloatRect textRect = _pText->getLocalBounds();
_pText->setOrigin(static_cast<int>(textRect.left + textRect.width / 2.0f), static_cast<int>(textRect.top + textRect.height / 2.0f));
 

Thanks everybody!

 

anything