source: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/OBAOgreApplication.cpp @ 909

Revision 909, 3.4 KB checked in by igarcia, 18 years ago (diff)
Line 
1
2#include "OBAOgreApplication.h"
3
4namespace OBA {
5
6OgreApplication::OgreApplication()
7{
8    mFrameListener = 0;
9    mRoot = 0;
10        mOgreBase = 0;
11}
12
13OgreApplication::~OgreApplication()
14{
15        // Gametools -- BUG: 31/03/2006
16        if (mFrameListener)
17        {
18                delete mFrameListener;
19        }
20
21        //if (mOgreBase)
22        //{
23        //      delete mOgreBase;
24        //}
25
26        //if (mRoot)
27        //{
28        //   delete mRoot;
29        //}
30}
31
32void OgreApplication::go(void)
33{         
34    // Set default mipmap level (NB some APIs ignore this)
35    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);       
36
37        // Create any resource listeners (for loading screens)
38        createResourceListener();
39
40    createFrameListener();
41
42    mRoot->startRendering();
43}
44
45bool OgreApplication::setup(bool createOgreRoot, Ogre::String applicationName, unsigned int width, unsigned int height, bool isFullScreen)
46{
47   // Change it when the texture generation will be included...
48
49   if (createOgreRoot)
50   {
51            mRoot = new Ogre::Root();
52   }
53   else
54   {
55           mOgreBase = new OBA::OgreBase();
56           mOgreBase->initialize();
57   }
58
59        configure(createOgreRoot, applicationName, width, height, isFullScreen);
60
61        if (createOgreRoot)
62        {
63                setupResources();
64
65                loadResources();
66        }
67
68    return true;
69}
70
71bool OgreApplication::configure(bool createOgreRoot, Ogre::String applicationName, unsigned int width, unsigned int height, bool isFullScreen)
72{
73        if (createOgreRoot)
74        {
75                // Show the configuration dialog and initialise the system
76                // You can skip this and use root.restoreConfig() to load configuration
77                // settings if you were sure there are valid ones saved in ogre.cfg
78                if(mRoot->showConfigDialog())
79                //if (mRoot->restoreConfig())
80                {
81                        // If returned true, user clicked OK so initialise
82                        // Here we choose to let the system create a default rendering window by passing 'true'
83                        //mWindow = mRoot->initialise(true);
84                        //mWindow->resize(512,512);
85                        mRoot->initialise(false);
86                        mWindow = mRoot->createRenderWindow(applicationName, width, height, isFullScreen);
87                       
88                        return true;
89                }
90                else
91                {
92                        return false;
93                }       
94        }
95        else
96        {
97                return true;
98        }
99}
100
101void OgreApplication::createFrameListener(void)
102{
103        OBA::OgreFrameListenerMode *defaultFrameListenerMode;
104       
105    mFrameListener = new OgreFrameListener(mWindow);
106        defaultFrameListenerMode =  mFrameListener->getFrameListenerMode(0);
107        mSceneMgr = defaultFrameListenerMode->getSceneManager();
108
109    mRoot->addFrameListener(mFrameListener);
110}
111
112void OgreApplication::setupResources(void)
113{
114    // Load resource paths from config file
115        Ogre::ConfigFile cf;
116    cf.load("resources.cfg");
117
118    // Go through all sections & settings in the file
119    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
120
121    Ogre::String secName, typeName, archName;
122    while (seci.hasMoreElements())
123    {
124        secName = seci.peekNextKey();
125        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
126        Ogre::ConfigFile::SettingsMultiMap::iterator i;
127        for (i = settings->begin(); i != settings->end(); ++i)
128        {
129            typeName = i->first;
130            archName = i->second;
131            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
132                archName, typeName, secName);
133        }
134    }
135}
136
137void OgreApplication::loadResources(void)
138{
139        // Initialise, parse scripts etc
140        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
141}
142
143void OgreApplication::createResourceListener(void)
144{
145}
146
147
148}
Note: See TracBrowser for help on using the repository browser.