您的位置:首页 > 编程语言 > Qt开发

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

2017-02-08 17:24 267 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ogre