SFML community forums

Help => Graphics => Topic started by: Lauthai on September 13, 2020, 05:02:11 pm

Title: Unicode Text Appearing as Boxes With Question Marks
Post by: Lauthai on September 13, 2020, 05:02:11 pm
Hello,

I am trying to get unicode characters working inside of my sfml based program written in C++.  I have tried using a wide string but when it draws on screen, it appears as a box with a question mark inside of it.  I am using the Consolas font when drawing the text.  I have my console set to use the same font and it draws the characters fine, but can't when drawn on screen.

Here is a simplified version of the code I am running:

// Creating of the render window
sf::RenderWindow gameWindow(sf::VideoMode(1920, 1080), "Game", sf::Style::Fullscreen);

// gameWindow is passed over to a thread so now I have a reference via pointer

// Load the font
sf::Font basicFont;
if (!basicFont.loadFromFile("Fonts/consola.ttf")) {
        wcerr << L"Can't load text" << endl;
        return;
}

// Create the basic text
sf::Text test;
test.setFont(basicFont);
test.setString(L"君の魂");
test.setPosition(500.f,500.f);
test.setCharacterSize(40);
test.setFillColor(sf::Color::White);
gameWindow->draw(test);
 
The font is loaded successfully and that return statement never called.

I have also attached the consola.ttf since maybe there is a problem with that.

I'm not sure exactly why it is unable to draw those characters.
Title: Re: Unicode Text Appearing as Boxes With Question Marks
Post by: G. on September 13, 2020, 05:20:39 pm
I think your font doesn't support japanese characters. 🤔
https://docs.microsoft.com/en-us/typography/font-list/consolas
Title: Re: Unicode Text Appearing as Boxes With Question Marks
Post by: Lauthai on September 13, 2020, 05:26:54 pm
I think your font doesn't support japanese characters. 🤔
https://docs.microsoft.com/en-us/typography/font-list/consolas

Interesting...I'm surprised that it worked when displaying in the command prompt then.  I'll try a different font and see if that fixes anything.
Title: Re: Unicode Text Appearing as Boxes With Question Marks
Post by: Lauthai on September 13, 2020, 05:33:37 pm
A new font seemed to fix it.  Thank you.
Title: Re: Unicode Text Appearing as Boxes With Question Marks
Post by: eXpl0it3r on September 16, 2020, 07:54:41 am
Interesting...I'm surprised that it worked when displaying in the command prompt then.  I'll try a different font and see if that fixes anything.
They probably have some fallback font defined for other character sets.
Title: Re: Unicode Text Appearing as Boxes With Question Marks
Post by: Hapax on September 27, 2020, 10:01:44 pm
Just wanted to say that I'm curious about what you game is about if that is the text that you are trying to display! ;)