Ogre 嵌入 Qt
使用的:OgreMovableText 類會造成程序崩潰,錯誤代碼:
mpFont = FontManager::getSingleton().getByName(mFontName);解決方法: 在使用OgreMovableText 類前,先在主程序構(gòu)造函數(shù)中進(jìn)行初始化、預(yù)加載操作:
// 初始化、預(yù)加載字體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;}創(chuàng)建中文文字:
// 顯示中文文字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);新聞熱點(diǎn)
疑難解答