Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/ReferenceApplication/Common/include/ExampleRefAppApplication.h @ 13

Last change on this file since 13 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 5.9 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10You may use this sample code for anything you like, it is not covered by the
11LGPL like the rest of the engine.
12-----------------------------------------------------------------------------
13*/
14
15/*
16-----------------------------------------------------------------------------
17Filename:    ExampleApplication.h
18Description: Base class for all the OGRE ReferenceApplication examples
19-----------------------------------------------------------------------------
20*/
21
22#ifndef __ExampleRefAppApplication_H__
23#define __ExampleRefAppApplication_H__
24
25#include "OgreReferenceAppLayer.h"
26#include "OgreConfigFile.h"
27#include "ExampleRefAppFrameListener.h"
28
29#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
30#    include <SDL.h>
31#endif
32
33using namespace Ogre;
34using namespace OgreRefApp;
35
36/** Base class which manages the standard startup of an Ogre application
37    based on the ReferenceApplication layer.
38    Designed to be subclassed for specific examples if required.
39*/
40class ExampleRefAppApplication
41{
42public:
43    /// Standard constructor
44    ExampleRefAppApplication()
45    {
46        mFrameListener = 0;
47        mRoot = 0;
48        mWorld = 0;
49    }
50    /// Standard destructor
51    virtual ~ExampleRefAppApplication()
52    {
53        if (mFrameListener)
54            delete mFrameListener;
55        if (mWorld)
56            delete mWorld;
57        if (mRoot)
58            delete mRoot;
59    }
60
61    /// Start the example
62    virtual void go(void)
63    {
64        if (!setup())
65            return;
66
67        mRoot->startRendering();
68    }
69
70protected:
71    Root *mRoot;
72    CollideCamera* mCamera;
73    SceneManager* mSceneMgr;
74    FrameListener* mFrameListener;
75    RenderWindow* mWindow;
76    World* mWorld;
77
78    // These internal methods package up the stages in the startup process
79    /** Sets up the application - returns false if the user chooses to abandon configuration. */
80    virtual bool setup(void)
81    {
82        mRoot = new Root();
83
84        setupResources();
85
86        bool carryOn = configure();
87        if (!carryOn) return false;
88
89        chooseSceneManager();
90        createWorld();
91        createCamera();
92        createViewports();
93
94        // Set default mipmap level (NB some APIs ignore this)
95        TextureManager::getSingleton().setDefaultNumMipmaps(5);
96
97                // Create any resource listeners (for loading screens)
98                createResourceListener();
99                // Load resources
100                loadResources();
101
102        // Create the scene
103        createScene();
104
105        createFrameListener();
106
107        return true;
108
109    }
110    /** Configures the application - returns false if the user chooses to abandon configuration. */
111    virtual bool configure(void)
112    {
113        // Show the configuration dialog and initialise the system
114        // You can skip this and use root.restoreConfig() to load configuration
115        // settings if you were sure there are valid ones saved in ogre.cfg
116        if(mRoot->showConfigDialog())
117        {
118            // If returned true, user clicked OK so initialise
119            // Here we choose to let the system create a default rendering window by passing 'true'
120            mWindow = mRoot->initialise(true);
121            return true;
122        }
123        else
124        {
125            return false;
126        }
127    }
128
129    virtual void chooseSceneManager(void)
130    {
131        // Get the SceneManager, in this case a generic one
132        mSceneMgr = mRoot->createSceneManager(ST_GENERIC, "RefAppSMInstance");
133    }
134    virtual void createCamera(void)
135    {
136        // Create the camera
137        mCamera = mWorld->createCamera("PlayerCam");
138
139        // Position it at 500 in Z direction
140        mCamera->setPosition(Vector3(0,0,500));
141        // Look back along -Z
142        mCamera->lookAt(Vector3(0,0,-300));
143        mCamera->setNearClipDistance(5);
144
145    }
146    virtual void createFrameListener(void)
147    {
148        mFrameListener= new ExampleRefAppFrameListener(mWindow, mCamera);
149        mRoot->addFrameListener(mFrameListener);
150    }
151
152    virtual void createScene(void) = 0;    // pure virtual - this has to be overridden
153
154    virtual void createViewports(void)
155    {
156        // Create one viewport, entire window
157        Viewport* vp = mWindow->addViewport(mCamera->getRealCamera());
158        vp->setBackgroundColour(ColourValue(0,0,0));
159    }
160
161    /// Method which will define the source of resources (other than current folder)
162    virtual void setupResources(void)
163    {
164        // Load resource paths from config file
165        ConfigFile cf;
166        cf.load("resources.cfg");
167
168        // Go through all sections & settings in the file
169        ConfigFile::SectionIterator seci = cf.getSectionIterator();
170
171        String secName, typeName, archName;
172        while (seci.hasMoreElements())
173        {
174            secName = seci.peekNextKey();
175            ConfigFile::SettingsMultiMap *settings = seci.getNext();
176            ConfigFile::SettingsMultiMap::iterator i;
177            for (i = settings->begin(); i != settings->end(); ++i)
178            {
179                typeName = i->first;
180                archName = i->second;
181                ResourceGroupManager::getSingleton().addResourceLocation(
182                    archName, typeName, secName);
183            }
184        }
185    }
186    virtual void createWorld(void)
187    {
188        mWorld = new World(mSceneMgr);
189    }
190        /// Optional override method where you can create resource listeners (e.g. for loading screens)
191        virtual void createResourceListener(void)
192        {
193
194        }
195
196        /// Optional override method where you can perform resource group loading
197        /// Must at least do ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
198        virtual void loadResources(void)
199        {
200                // Initialise, parse scripts etc
201                ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
202
203        }
204
205
206
207};
208
209
210#endif
Note: See TracBrowser for help on using the repository browser.