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(); }
// Load a menu void Menu::setMenu(const String &menu, int selection) { static bool firstTime = true; mMenuName = menu; mNumItems = findMenuItems(); mSelection = selection; mNewState = -1; // Set the colors MaterialPtr mat = MaterialManager::getSingleton().getByName("BlockCenter"); mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setAlphaOperation(LBX_MODULATE, LBS_TEXTURE, LBS_MANUAL, 1.0f, 0.5f); mat = MaterialManager::getSingleton().getByName("BlockBorder"); mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setAlphaOperation(LBX_MODULATE, LBS_TEXTURE, LBS_MANUAL, 1.0f, 0.5f); for(int f=0; f<mNumItems; f++) dimItem(f); hilightItem(mSelection); // Black and White on Viewport *vp = gameApp->getRenderWindow()->getViewport(0); CompositorManager::getSingleton().setCompositorEnabled(vp, "B&W", true); // Scroller on OverlayManager::getSingleton().getByName("MenuScroller")->show(); // Show the menu show(); // Load the background if(firstTime && menu == "MainMenu") { gameApp->loadLevel("menubg.lua"); // Load the high scores hiscoreList.load(getHiscoreLocation(true)); firstTime = false; // Update the version string TextAreaOverlayElement *ver = static_cast<TextAreaOverlayElement*>(OverlayManager::getSingleton().getOverlayElement("VersionText")); ver->setCaption("v" VERSION); } // Update the options menu if(menu == "GameOptions") prepareOptionsItems(); else if(menu == "HighScores") hiscoreList.updateOverlay(); else if(menu == "TitleScreen") titleAlpha = 0.0f; else if(menu == "MainMenu") OverlayManager::getSingleton().getByName("Version")->show(); }
// Do the name entering void Menu::doEnterName(const OIS::KeyEvent &e) { bool typed = false; char ch = e.text; char *str = mNewName; // Check the input if(e.key == OIS::KC_BACK) { // Play a typing sound SoundSystem::getSingleton().playSound("typing"); str[mTextPos] = '\0'; mTextPos--; if(mTextPos < 0) mTextPos = 0; str[mTextPos] = '\0'; // Update mNewItem->setCaption(String(str) + "^"); } else if(e.key == OIS::KC_RETURN) { if(mTextPos > 0) { // Done, save hiscoreList.save(getHiscoreLocation(false)); mEnteringName = false; TextAreaOverlayElement *item = static_cast<TextAreaOverlayElement*>(OverlayManager::getSingleton().getOverlayElement("HighScores1")); item->setCaption("Back to main"); // Update mNewItem->setCaption(String(str)); hiscoreList.updateOverlay(); return; } } else if(ch >= 32 && ch <= 126) { // Add a character typed = true; str[mTextPos] = ch; } // Modify string if(typed) { // Play a typing sound SoundSystem::getSingleton().playSound("typing"); mTextPos++; if(mTextPos > NAME_LEN-1) mTextPos = NAME_LEN-1; str[mTextPos] = '\0'; // Update mNewItem->setCaption(String(str) + "^"); } }
//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); }
// Enter a new name to the high scores void Menu::enterName(int place) { mEnteringName = true; mNewScorePlace = place; mNewName = hiscoreList.mList[place].name; strcpy(mNewName, ""); mTextPos = 0; // Change the text TextAreaOverlayElement *item = static_cast<TextAreaOverlayElement*>(OverlayManager::getSingleton().getOverlayElement("HighScores1")); item->setCaption("Congratulations!"); // Change the colours mNewItem = item = static_cast<TextAreaOverlayElement*>(OverlayManager::getSingleton().getOverlayElement("Name" + StringConverter::toString(place+1))); item->setColourTop(ColourValue(0.7f, 0.7f, 0.7f)); item->setColourBottom(ColourValue(1,1,1)); mNewItem->setCaption("^"); item = static_cast<TextAreaOverlayElement*>(OverlayManager::getSingleton().getOverlayElement("Score" + StringConverter::toString(place+1))); item->setColourTop(ColourValue(0.7f, 0.7f, 0.7f)); item->setColourBottom(ColourValue(1,1,1)); }
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); }
// Update an options menu item void Menu::updateOptionsItem(int i, bool change) { TextAreaOverlayElement *item = static_cast<TextAreaOverlayElement*>(OverlayManager::getSingleton().getOverlayElement(mMenuName + StringConverter::toString(i+1))); Viewport *vp = gameApp->getRenderWindow()->getViewport(0); String itemText = item->getCaption(); itemText = itemText.substr(0, itemText.find_last_of(':')); itemText += ": "; String str; char volstr[16] = ""; Real vol = 0; switch(i) { // Bloom effect case MENU_OPTIONS_BLOOM: str = gameApp->mGameConfig->GetValue("graphics", "bloom", "on"); if(change) { if(str == "on") str = "off"; else if(str == "off") str = "on"; gameApp->mGameConfig->SetValue("graphics", "bloom", str.c_str()); CompositorManager::getSingleton().setCompositorEnabled(vp, "Bloom", (str != "off")); } item->setCaption(itemText + ((str == "on") ? "ON" : "OFF")); break; // Shadows case MENU_OPTIONS_SHADOWS: str = gameApp->mGameConfig->GetValue("graphics", "shadows", "on"); if(change) { if(str == "on") str = "off"; else if(str == "off") str = "on"; gameApp->mGameConfig->SetValue("graphics", "shadows", str.c_str()); mSceneMgr->setShadowTechnique((str == "off") ? SHADOWTYPE_NONE : SHADOWTYPE_STENCIL_ADDITIVE); } item->setCaption(itemText + ((str == "on") ? "ON" : "OFF")); break; // Dynamic lights case MENU_OPTIONS_DYN_LIGHTS: str = gameApp->mGameConfig->GetValue("graphics", "dynamic_lights", "on"); if(change) { if(str == "on") str = "off"; else if(str == "off") str = "on"; gameApp->mGameConfig->SetValue("graphics", "dynamic_lights", str.c_str()); } item->setCaption(itemText + ((str == "on") ? "ON" : "OFF")); break; // Dynamic light cast shadows case MENU_OPTIONS_DYN_LIGHT_SHADOWS: str = gameApp->mGameConfig->GetValue("graphics", "dynamic_light_shadows", "on"); if(change) { if(str == "on") str = "off"; else if(str == "off") str = "on"; gameApp->mGameConfig->SetValue("graphics", "dynamic_light_shadows", str.c_str()); } item->setCaption(itemText + ((str == "on") ? "ON" : "OFF")); break; // Sound volume case MENU_OPTIONS_SOUND_VOL: str = gameApp->mGameConfig->GetValue("audio", "volume", "1.0"); vol = StringConverter::parseReal(str); if(change) { vol += 0.1f; if((int)(vol*100.0f) > 100) vol = 0.0f; str = StringConverter::toString(vol); gameApp->mGameConfig->SetValue("audio", "volume", str.c_str()); // Play a test sound SoundSystem::getSingleton().setSoundVolume(vol); SoundSystem::getSingleton().playSound("mushroom1"); } //ivol = (int)(100 * vol); sprintf(volstr, "%.0f%%", vol*100.0f); item->setCaption(itemText + String(volstr)); break; // Music volume case MENU_OPTIONS_MUSIC_VOL: str = gameApp->mGameConfig->GetValue("audio", "music_volume", "0.5"); vol = StringConverter::parseReal(str); if(change) { vol += 0.1f; if((int)(vol*100.0f) > 100) vol = 0.0f; str = StringConverter::toString(vol); gameApp->mGameConfig->SetValue("audio", "music_volume", str.c_str()); SoundSystem::getSingleton().setMusicVolume(vol); } //ivol = (int)(100 * vol); sprintf(volstr, "%.0f%%", vol*100.0f); item->setCaption(itemText + String(volstr)); break; } }