I know there are many post about blurry text, but I feel the need to open a new Thread, since there are things I don't understand yet.
So, I tried to print a small text and discovered that (with the font I used) SFML can only draw clear texts , when certain sizes are used.
In my case SFML only prints clear, if I use the size 8 or a multiple of it.
Here is image which shows 9 sf::Text object starting with the character size 8 and incrementing to 16.
As you can see, all texts are printed clear(but some still ugly). To achieve this I used the object with the size 8 and scaled every string with it and had to turn smooth of the Font off. Note that all multiples of 8 would draw fine without such a trick. (btw the font used is Pokemon GB.ttf from
http://www.fontspace.com/jackster-productions/pokemon-gb)
On the right there are two screenshots from notepad written with the same font.
The top extract is drawn with the size 6 and the bottom one is written with the size 12, so that charactersize 8 is linked to font size 6 in Notepad and 16 equals 12.
So what exactly is meant with charactersize, since it doesnt provide the same result given by notepad, when using equal sizes. This would be my first question.
It is clear to me, that with this technique only multiples of 8 can be drawn correctly , since they only will result in an even scale factor.
Not using this technique will leave most sizes blurry.
The example above is given by the following code :
#include <SFML/Graphics.hpp>
#include <iostream>
//#define CLEAR_FONT // commented, SFML will only draw texts clear with size % 8 == 0
int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(320, 180), "SFML window 2.0");
// Create a graphical text to display
sf::Font font;
if (!font.loadFromFile("GB.ttf"))
return EXIT_FAILURE;
#ifdef CLEAR_FONT
// 'old' Sfml 1.6 trick
const sf::Texture* tex = &font.getTexture(8);
((sf::Texture*) tex)->setSmooth(false);
sf::Text MyTexts[9] = { sf::Text("Example", font, 8),
sf::Text("Example", font, 8),
sf::Text("Example", font, 8),
sf::Text("Example", font, 8),
sf::Text("Example", font, 8),
sf::Text("Example", font, 8),
sf::Text("Example", font, 8),
sf::Text("Example", font, 8),
sf::Text("Example", font, 8)};
for (unsigned int i = 1;i < 9;i++)
MyTexts[i].setScale( (i+8) / 8.0 , (i+8) / 8.0); // every text will be clear, even when zooming in ( e.g. by resize)
#else
sf::Text MyTexts[9] = { sf::Text("Example", font, 8), // will be clear, but blurry when zooming in ( e.g. by resize)
sf::Text("Example", font, 9),
sf::Text("Example", font, 10),
sf::Text("Example", font, 11),
sf::Text("Example", font, 12),
sf::Text("Example", font, 13),
sf::Text("Example", font, 14),
sf::Text("Example", font, 15),
sf::Text("Example", font, 16)}; // will be clear, but blurry when zooming in ( e.g. by resize)
#endif
float OffSet_Y = 1;
for (unsigned int i = 0;i < 9;i++)
{
MyTexts[i].setPosition(1.0,OffSet_Y);
OffSet_Y += MyTexts[i].getGlobalBounds().height + 2;
}
// Start the game loop
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed)
window.close();
}
// Clear screen
window.clear();
// Draw the string
for (unsigned int i = 0;i < 9;i++)
window.draw(MyTexts[i]);
// Update the window
window.display();
}
return EXIT_SUCCESS;
}
So using this font, I'm forced to only use the character size 8,16,24 and so on.
(If the picture is not available, it's in the attachment)
[attachment deleted by admin]