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

Author Topic: Blurry Font  (Read 10307 times)

0 Members and 1 Guest are viewing this topic.

Aremion

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • http://mr--x.bplaced.de
Blurry Font
« on: July 16, 2011, 09:41:00 pm »
Hi!
I loaded a font and created a text. But if I display it, it seems a bit blurry. I found a solution: I take the font and use .GetImage(Size).SetSmooth(false). In order to do that, I have to use const_cast, because GetImage() returns a constant reference. But I read, that you shouldn't do that if it's avoidable.
I use the latest SFML-Version; I've just compiled it.
Also, the documentation says to "sf::Image::SetSmooth": "The smooth filter is disabled by default.", which seems incorrect.
To conclude, is there another way to make the font sharp without the use of const_cast that I have overlooked?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Blurry Font
« Reply #1 on: July 17, 2011, 10:47:08 am »
I found that sharp images were producing worse results than smoothed ones, that's why fonts' images have this option enabled (and forced). But I guess that I should do more tests :)

Quote
Also, the documentation says to "sf::Image::SetSmooth": "The smooth filter is disabled by default.", which seems incorrect.

It's not incorrect, it's just that fonts make their internal image smooth.
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Blurry Font
« Reply #2 on: July 23, 2011, 12:34:02 am »
Laurent, please at least make this optional. My textdrawing results is really messy, and i cant figure out how to const_cast the image or fix it otherwise.

Screenshot: https://legacy.sfmluploads.org/cache/pics/73_uglyfont.png

And oh, if i make the text smaller (wich it will be) the text is so smooth its unreadable.

And oh again(another edit): The map, character and nametags are all drawn on another viewport that is in 2x, to get that sweet pixely retro feel. If it says anything.

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Blurry Font
« Reply #3 on: July 23, 2011, 06:05:08 am »
Quote from: "Haikarainen"
i cant figure out how to const_cast the image or fix it otherwise.


Untested, but it compiles:
Code: [Select]
Font* f = MyCustomLoadFontMethod();
((Image&)f->GetImage(30U)).SetSmooth(false);

Haikarainen

  • Guest
Blurry Font
« Reply #4 on: July 23, 2011, 10:27:50 am »
Quote from: "JAssange"
Untested, but it compiles:
Code: [Select]
Font* f = MyCustomLoadFontMethod();
((Image&)f->GetImage(30U)).SetSmooth(false);


Thanks a load :) That works (had to do some obvious changes tho)

Edit, if anyone wonders what i had to do to make that code work on my system;

Remove the U and replace 30 with the fontsize im using.
Append sf:: before Image. Replace the pointer -> to a dot . since my font wasn't a pointer :)

And last but not least; Set the textsize your drawing to the fontsize it's using

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Blurry Font
« Reply #5 on: July 23, 2011, 01:15:08 pm »
And did that solve your problem?
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Blurry Font
« Reply #6 on: July 23, 2011, 02:38:35 pm »
Quote from: "Laurent"
And did that solve your problem?


It did, but i still think a sf::Font::SetSmooth() would be nice.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Blurry Font
« Reply #7 on: July 23, 2011, 04:34:25 pm »
You can't meaningfully cast arbitrary types to each other. If you do, you should at least use reinterpret_cast.

Anyway, this code evokes undefined behavior. I can't imagine it actually works. Even if it does right now, it is likely to mess up your whole program in a slightly different situation, not to mention another compiler. You should really not do that unless you like long debug sessions.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Blurry Font
« Reply #8 on: July 23, 2011, 06:08:55 pm »
Quote from: "Nexus"
You can't meaningfully cast arbitrary types to each other. If you do, you should at least use reinterpret_cast.

Anyway, this code evokes undefined behavior. I can't imagine it actually works. Even if it does right now, it is likely to mess up your whole program in a slightly different situation, not to mention another compiler. You should really not do that unless you like long debug sessions.

Casting away constness isn't, in and of itself, undefined behavior. Because the image GetImage returns isn't fundamentally const, it won't be in Read-Only memory, the Standard explicitly allows this case.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Blurry Font
« Reply #9 on: July 23, 2011, 06:10:40 pm »
Quote
You can't meaningfully cast arbitrary types to each other. If you do, you should at least use reinterpret_cast.

?
He's just casting a const sf::Image& to a sf::Image&. It's perfectly valid (at least technically).

Quote
It did, but i still think a sf::Font::SetSmooth() would be nice.

Yeah... I just want to make sure it is really necessary before implementing it. My previous tests showed that unsmoothed fonts always looked worse than smoothed ones, so I'm a little surprised.
Laurent Gomila - SFML developer

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Blurry Font
« Reply #10 on: July 23, 2011, 06:14:28 pm »
Quote from: "Laurent"
?
He's just casting a const sf::Image& to a sf::Image&. It's perfectly valid (at least technically).

I think he thought it was casting the Font to an Image.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Blurry Font
« Reply #11 on: July 23, 2011, 07:42:59 pm »
Quote from: "JAssange"
I think he thought it was casting the Font to an Image.
Indeed, I thought f is cast, didn't look close enough at it. Sorry ;)

Anyway, you should still prefer const_cast over C style casts :P
(Then one would directly see what happens and not confuse it like me)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Haikarainen

  • Guest
Blurry Font
« Reply #12 on: July 23, 2011, 11:39:24 pm »
Quote from: "Laurent"
Yeah... I just want to make sure it is really necessary before implementing it. My previous tests showed that unsmoothed fonts always looked worse than smoothed ones, so I'm a little surprised.


Hehe, generally they truly do, but for small fonts, and especially small fonts that has a pixely look(like in my case) i really need unsmoothed font.

Both technical, to fit a lot of text into a small view, and visual, to get that sweet retro feel :)

Just look at this: https://legacy.sfmluploads.org/cache/pics/75_pixelytext.png

Compared to this: https://legacy.sfmluploads.org/cache/pics/73_uglyfont.png

coolhome

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Blurry Font
« Reply #13 on: July 26, 2011, 06:38:40 am »
Quote from: "Laurent"
Yeah... I just want to make sure it is really necessary before implementing it. My previous tests showed that unsmoothed fonts always looked worse than smoothed ones, so I'm a little surprised.


I would be game for sf::Font::SetSmooth. That little trick posted above fixed everything in my project. :)
CoderZilla - Everything Programming

 

anything