1 | |
---|
2 | #include "OBAOgreApplication.h" |
---|
3 | |
---|
4 | namespace OBA { |
---|
5 | |
---|
6 | OgreApplication::OgreApplication() |
---|
7 | {
|
---|
8 | mFrameListener = 0;
|
---|
9 | mRoot = 0;
|
---|
10 | mOgreBase = 0;
|
---|
11 | } |
---|
12 | |
---|
13 | OgreApplication::~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 | |
---|
32 | void 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 | |
---|
45 | bool 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 | |
---|
71 | bool 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 | //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 | |
---|
101 | void OgreApplication::createFrameListener(void)
|
---|
102 | {
|
---|
103 | mFrameListener = new OgreFrameListener(mWindow);
|
---|
104 |
|
---|
105 | mRoot->addFrameListener(mFrameListener);
|
---|
106 | } |
---|
107 | |
---|
108 | void OgreApplication::setupResources(void)
|
---|
109 | {
|
---|
110 | // Load resource paths from config file
|
---|
111 | Ogre::ConfigFile cf;
|
---|
112 | cf.load("resources.cfg");
|
---|
113 |
|
---|
114 | // Go through all sections & settings in the file
|
---|
115 | Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
|
---|
116 |
|
---|
117 | Ogre::String secName, typeName, archName;
|
---|
118 | while (seci.hasMoreElements())
|
---|
119 | {
|
---|
120 | secName = seci.peekNextKey();
|
---|
121 | Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
|
---|
122 | Ogre::ConfigFile::SettingsMultiMap::iterator i;
|
---|
123 | for (i = settings->begin(); i != settings->end(); ++i)
|
---|
124 | {
|
---|
125 | typeName = i->first;
|
---|
126 | archName = i->second;
|
---|
127 | Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
|
---|
128 | archName, typeName, secName);
|
---|
129 | }
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | void OgreApplication::loadResources(void)
|
---|
134 | {
|
---|
135 | // Initialise, parse scripts etc
|
---|
136 | Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
|
---|
137 | }
|
---|
138 | |
---|
139 | void OgreApplication::createResourceListener(void) |
---|
140 | { |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | } |
---|