std::string Menu::chopString(const std::string& src, const float h, const Ogre::FontPtr& glyphs) { if (h<=0.0f or glyphs.isNull()) return src; const float maxWidth = 1.05; unsigned int i; std::string result = ""; float currentWidth = 0.0f; for (i=0; i<src.size(); ++i) { if (src.at(i)=='\n') { currentWidth = 0.0f; result.append(1, '\n'); } else { const float add_w = glyphs->getGlyphAspectRatio(src.at(i))*h; if (currentWidth+add_w>maxWidth) { result = result+"\n"+src.at(i); currentWidth = add_w; }//if else { result = result + src.at(i); currentWidth = currentWidth + add_w; }//else }//else }//for return result; }
void CServer::setupOgreResources() { ////////////////// // OGRE // ////////////////// // Carga las rutas de los recursos desde el archivo de configuración Ogre::ConfigFile cf; cf.load("resources.cfg"); // Examina todos los ajustes en el archivo Ogre::ConfigFile::SectionIterator itSection = cf.getSectionIterator(); std::string sSection, sType, sArch; while(itSection.hasMoreElements()) { sSection = itSection.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *mapSettings = itSection.getNext(); Ogre::ConfigFile::SettingsMultiMap::const_iterator itSetting = mapSettings->begin(); while(itSetting != mapSettings->end()) { sType = itSetting->first; sArch = itSetting->second; Ogre::ResourceGroupManager::getSingleton(). addResourceLocation(sArch, sType, sSection); ++itSetting; } } OGRE_NEW Ogre::FontManager(); Ogre::FontPtr font = (Ogre::FontPtr)Ogre::FontManager::getSingletonPtr()->create("bluehigh","General"); font->setParameter("MovableText","truetype"); // set the .ttf file name font->setParameter("source","bluehigh.ttf"); // set the size font->setParameter("size","18"); // set the dpi font->setParameter("resolution","96"); Ogre::FontPtr font2 = (Ogre::FontPtr)Ogre::FontManager::getSingletonPtr()->create("TESFont","General"); font2->setParameter("StaticText","truetype"); // set the .ttf file name font2->setParameter("source","TESFont.ttf"); // set the size font2->setParameter("size","18"); // set the dpi font2->setParameter("resolution","96"); } // setupResources
void gkDebugScreen::initialize() { if (m_isInit) return; try { m_font = new gkBuiltinFont; Ogre::FontPtr fp = Ogre::FontManager::getSingleton().create("<gkBuiltin/Font>", GK_BUILTIN_GROUP, true, m_font); fp->load(); Ogre::OverlayManager& mgr = Ogre::OverlayManager::getSingleton(); m_over = mgr.create("<gkBuiltin/gkDebugScreen>"); m_ele = mgr.createOverlayElement("TextArea", "<gkBuiltin/gkDebugScreen/TextArea>"); Ogre::OverlayContainer* cont = (Ogre::OverlayContainer*)mgr.createOverlayElement("BorderPanel", "<gkBuiltin/gkDebugScreen/Containter>"); cont->setMetricsMode(Ogre::GMM_PIXELS); cont->setVerticalAlignment(Ogre::GVA_TOP); const gkVector2& dims = gkWindowSystem::getSingleton().getMouse()->winsize; m_ele->setMetricsMode(Ogre::GMM_PIXELS); m_ele->setVerticalAlignment(Ogre::GVA_TOP); m_ele->setPosition(0, 0); m_ele->setDimensions(dims.x, dims.y); Ogre::TextAreaOverlayElement* textArea = static_cast<Ogre::TextAreaOverlayElement*>(m_ele); textArea->setFontName("<gkBuiltin/Font>"); textArea->setCharHeight(SCREEN_SIZE); textArea->setColour(Ogre::ColourValue::White); m_over->setZOrder(500); cont->addChild(m_ele); m_over->add2D(cont); } catch (Ogre::Exception& e) { gkPrintf("%s", e.getDescription().c_str()); return; } m_isInit = true; gConsole = this; }
void gkDebugScreen::initialize() { if (m_isInit) return; try { m_font = new gkBuiltinFont; Ogre::FontPtr fp = Ogre::FontManager::getSingleton().create("<gkBuiltin/Font>", GK_BUILTIN_GROUP, true, m_font); fp->load(); #define FONT_MATERIAL 1 #if FONT_MATERIAL #ifndef OGREKIT_USE_OLD gkString ShareMaterail = "Examples/BumpMapping/MultiLight"; static int Use_Init_Once = 0; if(Use_Init_Once < 2) { Ogre::FileInfoListPtr fileInfoList = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo( "", "*.material"); for (Ogre::FileInfoList::const_iterator cit=fileInfoList->begin(); cit != fileInfoList->end(); ++cit) { const Ogre::String& name = cit->filename; const Ogre::String& basename = cit->basename; Ogre::String sType = cit->archive->getType(); Ogre::String sPath = cit->archive->getName(); if (sType=="Zip" || sType=="FileSystem") { Ogre::DataStreamPtr pData= Ogre::ResourceGroupManager::getSingleton().openResource( basename,""); Ogre::MaterialManager::getSingleton().parseScript( pData, ""); Ogre::MaterialManager::getSingleton().load(basename,""); } } Use_Init_Once++; } #endif Ogre::MaterialPtr ShareMaterailPtr = Ogre::MaterialManager::getSingleton().getByName(ShareMaterail, ""); if (!ShareMaterailPtr.isNull()) { ShareMaterailPtr->load(); //ShareMaterailPtr->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("textureCount",1); } Ogre::MaterialPtr oma = Ogre::MaterialManager::getSingleton().getByName("Fonts/<gkBuiltin/Font>"); if (!oma.isNull()) { Ogre::Pass* pass1 = oma->getTechnique(0)->getPass(0); Ogre::GpuProgramPtr vsPtr = Ogre::HighLevelGpuProgramManager::getSingleton().getByName("FixVs"); if (vsPtr.isNull()) { LogManager::getSingleton().logMessage("GpuProgramPtr NULL"); } gkString VertexProgramName = "FixVs"; gkString FragmentProgramName ="FixPs"; if (pass1) { pass1->setVertexProgram(VertexProgramName); pass1->setFragmentProgram(FragmentProgramName); Ogre::GpuProgramParametersSharedPtr vsParams = pass1->getVertexProgramParameters(); vsParams->copyMatchingNamedConstantsFrom(*ShareMaterailPtr->getTechnique(0)->getPass(0)->getVertexProgramParameters().get()); Ogre::GpuProgramParametersSharedPtr psParams = pass1->getFragmentProgramParameters(); psParams->copyMatchingNamedConstantsFrom(*ShareMaterailPtr->getTechnique(0)->getPass(0)->getFragmentProgramParameters().get()); //psParams->setNamedConstant("textureCount",1); //psParams->setNamedConstant("AlphaValue",0.0f); //vsParams->setNamedConstant("lightOpen",0); LogManager::getSingleton().logMessage("set font es2.0"); } } #endif Ogre::OverlayManager& mgr = Ogre::OverlayManager::getSingleton(); m_over = mgr.create("<gkBuiltin/gkDebugScreen>"); m_ele = mgr.createOverlayElement("TextArea", "<gkBuiltin/gkDebugScreen/TextArea>"); Ogre::OverlayContainer* cont = (Ogre::OverlayContainer*)mgr.createOverlayElement("BorderPanel", "<gkBuiltin/gkDebugScreen/Containter>"); cont->setMetricsMode(Ogre::GMM_PIXELS); cont->setVerticalAlignment(Ogre::GVA_TOP); const gkVector2& dims = gkWindowSystem::getSingleton().getMouse()->winsize; m_ele->setMetricsMode(Ogre::GMM_PIXELS); m_ele->setVerticalAlignment(Ogre::GVA_TOP); m_ele->setPosition(0, 0); m_ele->setDimensions(dims.x, dims.y); Ogre::TextAreaOverlayElement* textArea = static_cast<Ogre::TextAreaOverlayElement*>(m_ele); textArea->setFontName("<gkBuiltin/Font>"); textArea->setCharHeight(SCREEN_SIZE); textArea->setColour(Ogre::ColourValue::White); m_over->setZOrder(500); cont->addChild(m_ele); m_over->add2D(cont); } catch (Ogre::Exception& e) { gkPrintf("%s", e.getDescription().c_str()); return; } m_isInit = true; gConsole = this; }
void gkFontManager::parseScript(utMemoryStream* buffer) { utScript script; script.parseBuffer("FontManager:parseScript", gkString((const char*)buffer->ptr())); utScriptTree* treePtr = script.getTreePtr(); if (treePtr->getNodes().empty()) return; utScriptTree::Nodes::Iterator niter = treePtr->getNodes().iterator(); while (niter.hasMoreElements()) { utScriptNode* tree = niter.getNext(); if (!tree->hasAttribute("source")) { gkLogMessage("FontManager: Missing font script attribute 'source'"); continue; } const gkString src = tree->getAttribute("source")->getValue(); if (!exists(src)) { gkLogMessage("FontManager: Missing internal font " << src); continue; } const gkString name = tree->getType(); Ogre::FontPtr fp = Ogre::FontManager::getSingleton().getByName(name); if (!fp.isNull()) { // use it return; } gkFont* gkf = (gkFont*)getByName(src); int size = 0, res = UT_NPOS; if (tree->hasAttribute("size")) gkFromString(tree->getAttribute("size")->getValue(), size); if (tree->hasAttribute("resolution")) gkFromString(tree->getAttribute("resolution")->getValue(), res); try { gkFont::Loader* fl = gkf->addLoader(size > 0 && size != UT_NPOS ? size : 12, res != UT_NPOS ? res : 55); fp = Ogre::FontManager::getSingleton().create(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true, fl); fl->setFont(fp.getPointer()); } catch (Ogre::Exception& e) { gkLogMessage("FontManager::parseScript: " << e.getDescription()); } } }