1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | /*
|
---|
26 | -----------------------------------------------------------------------------
|
---|
27 | Filename: ExampleApplication.h
|
---|
28 | Description: Base class for all the OGRE examples
|
---|
29 | -----------------------------------------------------------------------------
|
---|
30 | */
|
---|
31 |
|
---|
32 | #ifndef __ExampleApplication_H__
|
---|
33 | #define __ExampleApplication_H__
|
---|
34 |
|
---|
35 | #include "Ogre.h"
|
---|
36 | #include "OgreConfigFile.h"
|
---|
37 | #include "ExampleFrameListener.h"
|
---|
38 |
|
---|
39 |
|
---|
40 | using namespace Ogre;
|
---|
41 |
|
---|
42 | /** Base class which manages the standard startup of an Ogre application.
|
---|
43 | Designed to be subclassed for specific examples if required.
|
---|
44 | */
|
---|
45 | class ExampleApplication
|
---|
46 | {
|
---|
47 | public:
|
---|
48 | /// Standard constructor
|
---|
49 | ExampleApplication()
|
---|
50 | {
|
---|
51 | mFrameListener = 0;
|
---|
52 | mRoot = 0;
|
---|
53 | }
|
---|
54 | /// Standard destructor
|
---|
55 | virtual ~ExampleApplication()
|
---|
56 | {
|
---|
57 | if (mFrameListener)
|
---|
58 | delete mFrameListener;
|
---|
59 | if (mRoot)
|
---|
60 | delete mRoot;
|
---|
61 | }
|
---|
62 |
|
---|
63 | /// Start the example
|
---|
64 | virtual void go(void)
|
---|
65 | {
|
---|
66 | if (!setup())
|
---|
67 | return;
|
---|
68 |
|
---|
69 | mRoot->startRendering();
|
---|
70 | }
|
---|
71 |
|
---|
72 | protected:
|
---|
73 | Root *mRoot;
|
---|
74 | Camera* mCamera;
|
---|
75 | SceneManager* mSceneMgr;
|
---|
76 | FrameListener* mFrameListener;
|
---|
77 | RenderWindow* mWindow;
|
---|
78 |
|
---|
79 | // These internal methods package up the stages in the startup process
|
---|
80 | /** Sets up the application - returns false if the user chooses to abandon configuration. */
|
---|
81 | virtual bool setup(void)
|
---|
82 | {
|
---|
83 | mRoot = new Root();
|
---|
84 |
|
---|
85 | setupResources();
|
---|
86 |
|
---|
87 | // We choose only the OpenGL rendering subsystem
|
---|
88 | // If it does not exist, the initialise call will exit with the
|
---|
89 | // #2 "Cannot initialise - no render system has been selected.." error
|
---|
90 | Ogre::RenderSystemList::iterator pRend = mRoot->getAvailableRenderers()->begin();
|
---|
91 | while (pRend != mRoot->getAvailableRenderers()->end())
|
---|
92 | {
|
---|
93 | if ((*pRend)->getName() == "OpenGL Rendering Subsystem")
|
---|
94 | mRoot->setRenderSystem(*pRend);
|
---|
95 | pRend++;
|
---|
96 | }
|
---|
97 |
|
---|
98 | mRoot->initialise(false);
|
---|
99 | setupGTKWindow();
|
---|
100 |
|
---|
101 | chooseSceneManager();
|
---|
102 |
|
---|
103 | createCamera();
|
---|
104 | createViewports();
|
---|
105 |
|
---|
106 | // Set default mipmap level (NB some APIs ignore this)
|
---|
107 | TextureManager::getSingleton().setDefaultNumMipmaps(5);
|
---|
108 |
|
---|
109 | // Create the scene
|
---|
110 | createScene();
|
---|
111 |
|
---|
112 | createFrameListener();
|
---|
113 |
|
---|
114 | return true;
|
---|
115 |
|
---|
116 | }
|
---|
117 |
|
---|
118 | virtual void chooseSceneManager(void)
|
---|
119 | {
|
---|
120 | // Get the SceneManager, in this case a generic one
|
---|
121 | mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
|
---|
122 | }
|
---|
123 | virtual void createCamera(void)
|
---|
124 | {
|
---|
125 | // Create the camera
|
---|
126 | mCamera = mSceneMgr->createCamera("PlayerCam");
|
---|
127 |
|
---|
128 | // Position it at 500 in Z direction
|
---|
129 | mCamera->setPosition(Vector3(0,0,500));
|
---|
130 | // Look back along -Z
|
---|
131 | mCamera->lookAt(Vector3(0,0,-300));
|
---|
132 | mCamera->setNearClipDistance(5);
|
---|
133 |
|
---|
134 | }
|
---|
135 | virtual void createFrameListener(void) = 0;
|
---|
136 |
|
---|
137 | virtual void createScene(void) = 0; // pure virtual - this has to be overridden
|
---|
138 |
|
---|
139 | virtual void createViewports(void)
|
---|
140 | {
|
---|
141 | // Create one viewport, entire window
|
---|
142 | Viewport* vp = mWindow->addViewport(mCamera);
|
---|
143 | vp->setBackgroundColour(ColourValue(0,0,0));
|
---|
144 | }
|
---|
145 |
|
---|
146 | /// Method which will define the source of resources (other than current folder)
|
---|
147 | virtual void setupResources(void)
|
---|
148 | {
|
---|
149 | // Load resource paths from config file
|
---|
150 | ConfigFile cf;
|
---|
151 | cf.load("resources.cfg");
|
---|
152 |
|
---|
153 | // Go through all settings in the file
|
---|
154 | ConfigFile::SettingsIterator i = cf.getSettingsIterator();
|
---|
155 |
|
---|
156 | String typeName, archName;
|
---|
157 | while (i.hasMoreElements())
|
---|
158 | {
|
---|
159 | typeName = i.peekNextKey();
|
---|
160 | archName = i.getNext();
|
---|
161 | ResourceManager::addCommonArchiveEx( archName, typeName );
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | virtual void setupGTKWindow(void) = 0;
|
---|
167 | };
|
---|
168 |
|
---|
169 |
|
---|
170 | #endif
|
---|