TextAreaOverlayElement *OverlayHelper::CreateTextArea(const char *instanceName, const char *fontName, OverlayContainer* parent) { TextAreaOverlayElement *element = (TextAreaOverlayElement *) OverlayManager::getSingleton().createOverlayElement("TextArea", instanceName); if (parent) parent->addChild(element); element->setFontName(fontName); return element; }
void OgreApp::createScene() { sceneMgr->setSkyBox(true, "Sky", 5, 8, 4000); sceneMgr->setAmbientLight(ColourValue(0.5f, 0.5f, 0.5f)); sceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); node = sceneMgr->getRootSceneNode()->createChildSceneNode("OgreHead"); ent = sceneMgr->createEntity("Ogre", "ogrehead.mesh"); node->attachObject(ent); node->setPosition(0, 50, 0); OgreAL::Sound *bgSound = soundManager->createSound("5.1 Test", "6chan.ogg", true); bgSound->setGain(2); bgSound->setRelativeToListener(true); bgSound->play(); node = sceneMgr->getRootSceneNode()->createChildSceneNode("CameraNode"); node->setPosition(0, 100, 100); node = node->createChildSceneNode("PitchNode"); node->attachObject(camera); node->attachObject(soundManager->getListener()); node->pitch(Ogre::Degree(-30)); // Create a ground plane Plane plane(Vector3::UNIT_Y, 0); MeshManager::getSingleton().createPlane("ground", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 15000,15000,20,20,true,1,5,5,Vector3::UNIT_Z); ent = sceneMgr->createEntity("GroundEntity", "ground"); sceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); ent->setMaterialName("Ground"); ent->setCastShadows(false); light = sceneMgr->createLight("sun"); light->setType(Light::LT_DIRECTIONAL); light->setDirection(-1,-1,-1); OverlayManager& overlayMgr = OverlayManager::getSingleton(); Ogre::OverlayContainer* panel = static_cast<OverlayContainer*>( overlayMgr.createOverlayElement("Panel", "PanelName")); panel->setMetricsMode(Ogre::GMM_PIXELS); panel->setPosition(10, 10); panel->setDimensions(100, 100); TextAreaOverlayElement* textArea = static_cast<TextAreaOverlayElement*>( overlayMgr.createOverlayElement("TextArea", "TextAreaName")); textArea->setMetricsMode(Ogre::GMM_PIXELS); textArea->setPosition(0, 0); textArea->setDimensions(100, 100); textArea->setCharHeight(16); textArea->setFontName("Arial"); textArea->setCaption("Hello, World!"); Ogre::Overlay* overlay = overlayMgr.create("AverageFps"); overlay->add2D(panel); panel->addChild(textArea); overlay->show(); }
//Grabbed from Ogre3D Wiki void Utility::drawText(Ogre::String tText, int tSize, Ogre::Vector2 tPosition, Ogre::ColourValue tTopColor, Ogre::ColourValue tBotColor) { // Create a text area TextAreaOverlayElement* textArea = static_cast<TextAreaOverlayElement*>( overlayManager->createOverlayElement( "TextArea", tText)); //"TextAreaName" + StringConverter::toString(Ogre::Timer::Timer().getMicrosecondsCPU()) ) ); textArea->setMetricsMode(Ogre::GMM_PIXELS); textArea->setPosition(tPosition.x, tPosition.y); textArea->setDimensions(100, 100); textArea->setCaption(tText); textArea->setCharHeight(tSize); textArea->setFontName("StarWars"); /*textArea->setColourBottom(ColourValue(0.3, 0.5, 0.3)); textArea->setColourTop(ColourValue(0.5, 0.7, 0.5));*/ textArea->setColourBottom(tBotColor); textArea->setColourTop(tTopColor); // Add the text area to the panel panel->addChild(textArea); }
void GameScreen::setUpOverlay(){ // Load the Font FontManager &fontMgr = FontManager::getSingleton(); ResourcePtr font = fontMgr.create("GameFont","General"); font->setParameter("type","truetype"); font->setParameter("source","Smirnof.ttf"); font->setParameter("size","20"); font->setParameter("resolution","96"); font->load(); // Load the overlay OverlayManager& overlayMgr = OverlayManager::getSingleton(); Ogre::OverlayContainer* panel = static_cast<OverlayContainer*>( overlayMgr.createOverlayElement("Panel", "PanelName")); panel->_setPosition(0.05, 0.925); panel->setDimensions(300, 120); TextAreaOverlayElement* textArea = static_cast<TextAreaOverlayElement*>( overlayMgr.createOverlayElement("TextArea", "TextAreaName")); textArea->setMetricsMode(Ogre::GMM_PIXELS); textArea->setPosition(0, 0); textArea->setDimensions(300, 120); textArea->setCharHeight(24); textArea->setColour(ColourValue(1,1,0)); // set the font name to the font resource that you just created. textArea->setFontName("GameFont"); // say something std::stringstream ss; ss << "Score: " << score; textArea->setCaption(ss.str().c_str()); overlay = overlayMgr.create("OverlayName"); overlay->add2D(panel); panel->addChild(textArea); }