Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Unicode Text Appearing as Boxes With Question Marks  (Read 3563 times)

0 Members and 1 Guest are viewing this topic.

Lauthai

  • Newbie
  • *
  • Posts: 6
    • View Profile
Unicode Text Appearing as Boxes With Question Marks
« 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.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Unicode Text Appearing as Boxes With Question Marks
« Reply #1 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

Lauthai

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Unicode Text Appearing as Boxes With Question Marks
« Reply #2 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.

Lauthai

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Unicode Text Appearing as Boxes With Question Marks
« Reply #3 on: September 13, 2020, 05:33:37 pm »
A new font seemed to fix it.  Thank you.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Unicode Text Appearing as Boxes With Question Marks
« Reply #4 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Unicode Text Appearing as Boxes With Question Marks
« Reply #5 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! ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*