Hello, I've been trying to get Japanese characters to render in SFML 2 RC to no avail. I've used the font from this thread (http://en.sfml-dev.org/forums/index.php?topic=5927.0) so that I know the font is compatible. Direct link for convenience (http://www.fonts2u.com/m-1p-medium.font).
The Japanese text comes up as question marks while English text displays normally. Sample code is below, thank you for reading:
#include <SFML/Graphics.hpp>
#include <SFML/System/Utf.hpp>
#include <iostream>
int main()
{
sf::Font font;
sf::String msg, hdr;
sf::Text text;
if(!font.loadFromFile("test.ttf"))
{
text.setString("Load failed");
hdr = "Warning!";
}
else
{
font.loadFromFile("test.ttf");
//char jp[2] = { '\u70B9','\u83DC' }; //error even worse here
//msg = jp;
msg = "こんにちはSMFL"; //tested this first, Japanese characters come up as "??????SMFL"
hdr = "こんにちはSMFL";
//Set up for potential conversion from different utf types
/*sf::Utf<8>::toUtf32(msg.begin(), msg.end(), msg.begin());
sf::Utf<8>::toUtf32(hdr.begin(), hdr.end(), hdr.begin());*/
text.setFont(font);
text.setString(msg);
}
sf::RenderWindow window(sf::VideoMode(300, 200), hdr);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(text);
window.display();
}
return 0;
}
You can't define Unicode characters in a "regular" string literal (made of 8-bit chars), you need at least a wide string literal.
msg = L"&#12371;&#12435;&#12395;&#12385;&#12399;SMFL";
hdr = L"&#12371;&#12435;&#12395;&#12385;&#12399;SMFL";
And by the way, it is SFML.
You can't define Unicode characters in a "regular" string literal (made of 8-bit chars), you need at least a wide string literal.
msg = L"&#12371;&#12435;&#12395;&#12385;&#12399;SMFL";
hdr = L"&#12371;&#12435;&#12395;&#12385;&#12399;SMFL";
That was the solution, thank you for your help!
And by the way, it is SFML.
Ah, sorry. Slip of the index ._.