0

I need to display UTF-8 characters in osg, however text->setText( test,osgText::String::ENCODING_UTF8 ); cannot display though, it's like ? in the scene. Does anybody have the same problem or know how to do it?

Code Snippet

osg::ref_ptr<osg::Geode> geode = new osg::Geode;
{
    osg::ref_ptr<osgText::Text> text = new osgText::Text; 
    text->setFont( "CAMBRIA.TTC" );
    //text->setFont( font.get() );
    text->setColor( white );
    text->setCharacterSize( characterSize );
    text->setPosition( OsgFunc::arrowArcTextPosition( centerPoint, centerPoint + osg::Vec3( -30, 0, 0 ), centerPoint + v ) + osg::Vec3d( 0, -5, 1 ) );
    text->setAxisAlignment( osgText::Text::SCREEN );
    text->setText( "\u03b2",osgText::String::ENCODING_UTF8 );
    geode->addDrawable( text.get() );
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
litaoshen
  • 1,762
  • 1
  • 20
  • 36
  • 1
    You need to use a font which has those characters in it. – Ben Dec 06 '13 at 17:04
  • Thank you for your response. I already checked this! I used this guy 'text->setFont( "CAMBRIA.TTC" )'; But it still cannot work. – litaoshen Dec 06 '13 at 17:39
  • **Post your code.** Perhaps the font is not being found? (e.g. if your font path is not set up). – Ben Dec 07 '13 at 09:44
  • I even copied the font file into the release folder, still cannot work@Ben, the original code is too long, I edited the question and added some code, thank you! – litaoshen Dec 07 '13 at 14:53
  • Are you sure the UTF-8 escape is supported by your compiler? Have you tried encoding it as `"\xCE\xB2"`?? – Ben Dec 07 '13 at 21:32
  • Actually I think you just haven't told the compiler it is a UTF-8 string literal: `text->setText(u"\u03b2",osgText::String::ENCODING_UTF8 );`... You told `setText` but the compiler also needs to be told so it can interpret the `\u` correctly. Also you need C++11 support for this. – Ben Dec 07 '13 at 21:42
  • Thank you so much! But I use VS2008 for this project!It is a legacy project that I maintain now. It uses Qt also. Do you think I can do something about it by using VS2008? People say that VS2008 cannot support c++11, I will test it when I go to lab. Thank you again! – litaoshen Dec 08 '13 at 19:54
  • Thank you so much @Ben ! It works now! Many many thanks to you! Also don't worry about C++11, VS2008 works! – litaoshen Dec 09 '13 at 05:31

0 Answers0