Ogre嵌入Qt:布告板显示中文(补充)

来源:互联网 发布:新手怎样开淘宝店 编辑:程序博客网 时间:2024/06/13 22:29

Ogre 嵌入 Qt

使用的:OgreMovableText 类会造成程序崩溃,错误代码:

mpFont = FontManager::getSingleton().getByName(mFontName);

解决方法:
在使用OgreMovableText 类前,先在主程序构造函数中进行初始化、预加载操作:

// 初始化、预加载字体bool createSceneFont(){    Ogre::OverlaySystem* pOverlaySystem = new Ogre::OverlaySystem();    m_pSceneManager->addRenderQueueListener(pOverlaySystem);    Ogre::FontPtr tempFont = static_cast<Ogre::FontPtr>(Ogre::FontManager::getSingleton().create("SdkTrays/Caption", "Popular"));    tempFont->setType(Ogre::FontType::FT_TRUETYPE); // 字体类型    tempFont->setSource("msyh.ttf");            // 字体源(微软雅黑)    tempFont->setTrueTypeResolution(96);        // 字体的打印分辨率,一般为96    tempFont->setTrueTypeSize(32);              // 字体大小: 生成纹理的大小,值越大生成纹理所花的时间也就越多    tempFont->addCodePointRange(Ogre::Font::CodePointRange(33,126));         // 英文-unicode的int值范围    tempFont->addCodePointRange(Ogre::Font::CodePointRange(19968,40869));    // 汉字-unicode的int值范围    m_font = tempFont;    m_font->load();    if (m_font.isNull())    {        return false;    }    return true;}

创建中文文字:

// 显示中文文字Ogre::SceneNode* nodeTemp = m_pSceneManager->getRootSceneNode()->createChildSceneNode("line");nodeTemp->setPosition(Ogre::Vector3(0, 0, 0));Ogre::ColourValue textColor = Ogre::ColourValue(0.5f, 0.0f, 1.0f);Ogre::DisplayString str = Ogre::DisplayString(L"食人魔");Ogre::MovableText* mt = new Ogre::MovableText("temp1", str, "SdkTrays/Caption", 1, textColor);mt->showOnTop(true);mt->setTextAlignment(Ogre::MovableText::HorizontalAlignment::H_CENTER, Ogre::MovableText::VerticalAlignment::V_ABOVE);nodeTemp->attachObject(mt);
0 0
原创粉丝点击