#include "OBAOgreApplication.h" namespace OBA { OgreApplication::OgreApplication() { mFrameListener = 0; mRoot = 0; mOgreBase = 0; } OgreApplication::~OgreApplication() { // Gametools -- BUG: 31/03/2006 if (mFrameListener) { delete mFrameListener; } //if (mOgreBase) //{ // delete mOgreBase; //} //if (mRoot) //{ // delete mRoot; //} } void OgreApplication::go(void) { // Set default mipmap level (NB some APIs ignore this) Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); // Create any resource listeners (for loading screens) createResourceListener(); createFrameListener(); mRoot->startRendering(); } bool OgreApplication::setup(bool createOgreRoot, Ogre::String applicationName, unsigned int width, unsigned int height, bool isFullScreen) { // Change it when the texture generation will be included... if (createOgreRoot) { mRoot = new Ogre::Root(); } else { mOgreBase = new OBA::OgreBase(); mOgreBase->initialize(); } configure(createOgreRoot, applicationName, width, height, isFullScreen); if (createOgreRoot) { setupResources(); loadResources(); } return true; } bool OgreApplication::configure(bool createOgreRoot, Ogre::String applicationName, unsigned int width, unsigned int height, bool isFullScreen) { if (createOgreRoot) { // Show the configuration dialog and initialise the system // You can skip this and use root.restoreConfig() to load configuration // settings if you were sure there are valid ones saved in ogre.cfg if(mRoot->showConfigDialog()) //if (mRoot->restoreConfig()) { // If returned true, user clicked OK so initialise // Here we choose to let the system create a default rendering window by passing 'true' //mWindow = mRoot->initialise(true); //mWindow->resize(512,512); mRoot->initialise(false); mWindow = mRoot->createRenderWindow(applicationName, width, height, isFullScreen); return true; } else { return false; } } else { return true; } } void OgreApplication::createFrameListener(void) { OBA::OgreFrameListenerMode *defaultFrameListenerMode; mFrameListener = new OgreFrameListener(mWindow); defaultFrameListenerMode = mFrameListener->getFrameListenerMode(0); mSceneMgr = defaultFrameListenerMode->getSceneManager(); mRoot->addFrameListener(mFrameListener); } void OgreApplication::setupResources(void) { // Load resource paths from config file Ogre::ConfigFile cf; cf.load("resources.cfg"); // Go through all sections & settings in the file Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); Ogre::String secName, typeName, archName; while (seci.hasMoreElements()) { secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; archName = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); } } } void OgreApplication::loadResources(void) { // Initialise, parse scripts etc Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); } void OgreApplication::createResourceListener(void) { } }