Changeset 399 for code/branches
- Timestamp:
- Dec 5, 2007, 3:44:06 PM (17 years ago)
- Location:
- code/branches/skybox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/skybox/bin/resources.cfg
r135 r399 9 9 FileSystem=../Media/fonts 10 10 #FileSystem=../Media/materials/programs 11 #FileSystem=../Media/materials/scripts11 FileSystem=../Media/materials/scripts 12 12 #FileSystem=../Media/materials/textures 13 13 #FileSystem=../Media/models 14 14 #FileSystem=../Media/overlays 15 15 #FileSystem=../Media/particle 16 FileSystem=../Media/gui16 #FileSystem=../Media/gui 17 17 #FileSystem=../Media/DeferredShadingMedia 18 18 #Zip=../Media/packs/cubemap.zip -
code/branches/skybox/src/orxonox.cc
r164 r399 33 33 #include <Ogre.h> 34 34 #include <OIS/OIS.h> 35 #include <CEGUI/CEGUI.h>36 #include <OgreCEGUIRenderer.h>35 //#include <CEGUI/CEGUI.h> 36 //#include <OgreCEGUIRenderer.h> 37 37 38 38 #include <string> 39 39 #include <iostream> 40 41 #include "xml/xmlParser.h"42 #include "loader/LevelLoader.h"43 44 45 // some tests to see if enet works without includsion46 //#include <enet/enet.h>47 //#include <enet/protocol.h>48 40 49 41 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE … … 74 66 #endif 75 67 68 namespace orxonox 69 { 70 class OrxExitListener : public Ogre::FrameListener 71 { 72 public: 73 OrxExitListener(OIS::Keyboard *keyboard) 74 : mKeyboard(keyboard) 75 { 76 } 77 78 bool frameStarted(const Ogre::FrameEvent& evt) 79 { 80 mKeyboard->capture(); 81 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 82 } 83 84 private: 85 OIS::Keyboard *mKeyboard; 86 }; 87 88 class OrxApplication 89 { 90 public: 91 void go() 92 { 93 createRoot(); 94 defineResources(); 95 setupRenderSystem(); 96 createRenderWindow(); 97 initializeResourceGroups(); 98 createScene(); 99 setupScene(); 100 setupInputSystem(); 101 setupCEGUI(); 102 createFrameListener(); 103 startRenderLoop(); 104 } 105 106 ~OrxApplication() 107 { 108 mInputManager->destroyInputObject(mKeyboard); 109 OIS::InputManager::destroyInputSystem(mInputManager); 110 111 delete mListener; 112 delete mRoot; 113 } 114 115 private: 116 Ogre::Root *mRoot; 117 OIS::Keyboard *mKeyboard; 118 OIS::Mouse *mMouse; 119 OIS::InputManager *mInputManager; 120 // CEGUI::OgreCEGUIRenderer *mRenderer; 121 // CEGUI::System *mSystem; 122 OrxExitListener *mListener; 123 124 void createRoot() 125 { 126 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 127 mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg"); 128 #else 129 mRoot = new Ogre::Root(); 130 #endif 131 } 132 133 void defineResources() 134 { 135 Ogre::String secName, typeName, archName; 136 Ogre::ConfigFile cf; 137 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 138 cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); 139 #else 140 cf.load("resources.cfg"); 141 #endif 142 143 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); 144 while (seci.hasMoreElements()) 145 { 146 secName = seci.peekNextKey(); 147 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); 148 Ogre::ConfigFile::SettingsMultiMap::iterator i; 149 for (i = settings->begin(); i != settings->end(); ++i) 150 { 151 typeName = i->first; 152 archName = i->second; 153 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 154 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName); 155 #else 156 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); 157 #endif 158 } 159 } 160 } 161 162 void setupRenderSystem() 163 { 164 if (!mRoot->restoreConfig() && !mRoot->showConfigDialog()) 165 throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); 166 } 167 168 void createRenderWindow() 169 { 170 mRoot->initialise(true, "Ogre Render Window"); 171 } 172 173 void initializeResourceGroups() 174 { 175 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 176 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 177 } 178 179 void createScene(void) 180 { 181 182 } 183 184 void setupScene() 185 { 186 Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 187 Ogre::Camera *cam = mgr->createCamera("Camera"); 188 cam->setPosition(Ogre::Vector3(0,0,-250)); 189 cam->lookAt(Ogre::Vector3(0,0,0)); 190 Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); 191 mgr->setSkyBox(true, "Examples/SpaceSkyBox"); 192 } 193 194 void setupInputSystem() 195 { 196 size_t windowHnd = 0; 197 std::ostringstream windowHndStr; 198 OIS::ParamList pl; 199 Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); 200 201 win->getCustomAttribute("WINDOW", &windowHnd); 202 windowHndStr << windowHnd; 203 pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 204 mInputManager = OIS::InputManager::createInputSystem(pl); 205 206 try 207 { 208 mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); 209 mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false)); 210 } 211 catch (const OIS::Exception &e) 212 { 213 throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem"); 214 } 215 } 216 217 void setupCEGUI() 218 { 219 Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager"); 220 Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); 221 } 222 223 void createFrameListener() 224 { 225 mListener = new OrxExitListener(mKeyboard); 226 mRoot->addFrameListener(mListener); 227 } 228 229 void startRenderLoop() 230 { 231 mRoot->startRendering(); 232 } 233 }; 234 } 235 76 236 using namespace Ogre; 77 78 class OrxExitListener : public FrameListener79 {80 public:81 OrxExitListener(OIS::Keyboard *keyboard)82 : mKeyboard(keyboard)83 {84 }85 86 bool frameStarted(const FrameEvent& evt)87 {88 mKeyboard->capture();89 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);90 }91 92 private:93 OIS::Keyboard *mKeyboard;94 };95 96 class OrxApplication97 {98 public:99 void go()100 {101 createRoot();102 defineResources();103 setupRenderSystem();104 createRenderWindow();105 initializeResourceGroups();106 createScene();107 setupScene();108 setupInputSystem();109 setupCEGUI();110 createFrameListener();111 startRenderLoop();112 }113 114 ~OrxApplication()115 {116 mInputManager->destroyInputObject(mKeyboard);117 OIS::InputManager::destroyInputSystem(mInputManager);118 119 // delete mRenderer;120 // delete mSystem;121 122 delete mListener;123 delete mRoot;124 }125 126 private:127 Root *mRoot;128 OIS::Keyboard *mKeyboard;129 OIS::Mouse *mMouse;130 OIS::InputManager *mInputManager;131 CEGUI::OgreCEGUIRenderer *mRenderer;132 CEGUI::System *mSystem;133 OrxExitListener *mListener;134 135 void createRoot()136 {137 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE138 mRoot = new Root(macBundlePath() + "/Contents/Resources/plugins.cfg");139 #else140 mRoot = new Root();141 #endif142 }143 144 void defineResources()145 {146 String secName, typeName, archName;147 ConfigFile cf;148 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE149 cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");150 #else151 cf.load("resources.cfg");152 #endif153 154 ConfigFile::SectionIterator seci = cf.getSectionIterator();155 while (seci.hasMoreElements())156 {157 secName = seci.peekNextKey();158 ConfigFile::SettingsMultiMap *settings = seci.getNext();159 ConfigFile::SettingsMultiMap::iterator i;160 for (i = settings->begin(); i != settings->end(); ++i)161 {162 typeName = i->first;163 archName = i->second;164 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE165 ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName);166 #else167 ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);168 #endif169 }170 }171 }172 173 void setupRenderSystem()174 {175 if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())176 throw Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");177 }178 179 void createRenderWindow()180 {181 mRoot->initialise(true, "Ogre Render Window");182 }183 184 void initializeResourceGroups()185 {186 TextureManager::getSingleton().setDefaultNumMipmaps(5);187 ResourceGroupManager::getSingleton().initialiseAllResourceGroups();188 }189 190 void createScene(void)191 {192 193 string levelFile = "sp_level_moonstation.oxw";194 loader::LevelLoader* loader = new loader::LevelLoader(levelFile);195 }196 197 void setupScene()198 {199 SceneManager *mgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager");200 Camera *cam = mgr->createCamera("Camera");201 Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);202 }203 204 void setupInputSystem()205 {206 size_t windowHnd = 0;207 std::ostringstream windowHndStr;208 OIS::ParamList pl;209 RenderWindow *win = mRoot->getAutoCreatedWindow();210 211 win->getCustomAttribute("WINDOW", &windowHnd);212 windowHndStr << windowHnd;213 pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));214 mInputManager = OIS::InputManager::createInputSystem(pl);215 216 try217 {218 mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));219 mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));220 }221 catch (const OIS::Exception &e)222 {223 throw new Exception(42, e.eText, "OrxApplication::setupInputSystem");224 }225 }226 227 void setupCEGUI()228 {229 SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");230 RenderWindow *win = mRoot->getAutoCreatedWindow();231 232 // CEGUI setup233 // mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr);234 // mSystem = new CEGUI::System(mRenderer);235 236 // Other CEGUI setup here.237 }238 239 void createFrameListener()240 {241 mListener = new OrxExitListener(mKeyboard);242 mRoot->addFrameListener(mListener);243 }244 245 void startRenderLoop()246 {247 mRoot->startRendering();248 }249 };250 237 251 238 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 … … 260 247 try 261 248 { 262 OrxApplication orxonox;249 orxonox::OrxApplication orxonox; 263 250 orxonox.go(); 264 251 }
Note: See TracChangeset
for help on using the changeset viewer.