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() );
}
8
  • 1
    You need to use a font which has those characters in it.
    – Ben
    Dec 6, 2013 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 6, 2013 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 7, 2013 at 9: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 7, 2013 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 7, 2013 at 21:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.