SFML community forums
Help => Graphics => Topic started by: zslevi on December 15, 2011, 10:09:52 pm
-
I've tried the font drawing tutorial program, worked without a problem. Then I tried to draw text that uses non-ASCII characters.
I read the text to be displayed from an UTF-8 file.
const sf::Uint8* readStringCpp(){
std::string line("");
std::ifstream mfile("utf8text.txt");
if (mfile.is_open()){
std::getline(mfile,line);
}
return (sf::Uint8*)line.c_str();
}
...
sf::Unicode::Text ucText(readStringCpp());
sf::String Hello(ucText);
Hello.SetFont(MyFont);
Hello.SetColor(sf::Color(0, 128, 128));
Hello.SetPosition(60.f, 120.f);
...
And choose Arial Unicode for font.
The standard text to test Hungarian characters is "Árvíztűrő tükörfúrógép". Most of the accented characters of this are already in ASCII, except for Ő and Ű.
What I've got:
http://i.imgur.com/dpHyN.png
As you can see, the non-ASCII characters didn't got displayed.
What did I wrong?
If I use wide character literals, I get the same.
-
Most of the accented characters of this are already in ASCII
ASCII only defines 128 characters. You're rather referring to one of the extended ASCII encodings, probably latin-1.
But anyway, your problem is that the font is loaded with a predefined character set, which probably doesn't contain the characters that you don't see.
Use the 3rd parameter of Font::LoadFromFile to specify a custom characters set. Or use SFML 2, which is easier.
-
Thanks, that was it, I somehow missed that for the first reading of the tutorial. However it would be nice to have some utility function initializing the characterset for a certain ISO-8859-x characterset for merely convenience.
-
There's no more explicit characters set to define in SFML 2.