SFML community forums

Help => Graphics => Topic started by: Aremion on July 16, 2011, 09:41:00 pm

Title: Blurry Font
Post by: Aremion 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?
Title: Blurry Font
Post by: Laurent 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.
Title: Blurry Font
Post by: Haikarainen 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.
Title: Blurry Font
Post by: JAssange 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);
Title: Blurry Font
Post by: Haikarainen 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
Title: Blurry Font
Post by: Laurent on July 23, 2011, 01:15:08 pm
And did that solve your problem?
Title: Blurry Font
Post by: Haikarainen 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.
Title: Blurry Font
Post by: Nexus 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.
Title: Blurry Font
Post by: JAssange 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.
Title: Blurry Font
Post by: Laurent 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.
Title: Blurry Font
Post by: JAssange 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.
Title: Blurry Font
Post by: Nexus 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)
Title: Blurry Font
Post by: Haikarainen 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
Title: Blurry Font
Post by: coolhome 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. :)