IMPORTANT: This framework is meant to be used with old releases of Ogre. For Ogre >= 1.10, rather use OgreBites::ApplicationContext.

Image

This page provides extensive information on the Ogre Wiki Tutorial Framework. This is the framework used for the Basic Tutorial series. If you're following the series, then you can just download the appropriate files and get back to the tutorials.

Downloads

Ogre 1.9 ("Ghadamon")

 Plugin disabled
Plugin attach cannot be executed.
 Plugin disabled
Plugin attach cannot be executed.

Motivation

Ogre is complicated. There is no getting around that. So it was decided that it would be useful to provide a universal framework that could serve as a starting point for building applications. The structure of the framework isn't necessarily how you should arrange your own Ogre applications. It was created specifically as a teaching tool.

Overview

The framework consists of two classes: BaseApplication and TutorialApplication.

BaseApplication is a pure virtual class, because it contains the pure virtual function createScene. Such a class can not be instantiated. Instead, it is meant to be used as a base class. If you're familiar with Java, then BaseApplication can be thought of somewhat like an interface. It is never meant to be used on its own.

TutorialApplication derives from BaseApplication, and therefore must implement its own version of createScene.

The BaseApplication Class

BaseApplication inherits from five different listeners:

class BaseApplication
  : public Ogre::FrameListener,
    public Ogre::WindowEventListener, 
    public OIS::KeyListener, 
    public OIS::MouseListener, 
    OgreBites::SdkTrayListener
  1. A FrameListener provides callback functions related to the steps involved in rendering frames. It includes functions like: frameStarted, frameRenderingQueued, and frameEnded. See Basic Tutorial 4 for more information.
  2. A WindowEventListener provides callback functions related to window events like clicking the close button. It includes functions like: windowClosed, windowMoved, and windowResized.
  3. A KeyListener is a class from OIS that provides callbacks related to keyboard events. It includes the functions: keyPressed and keyReleased.
  4. A MouseListener is a class from OIS that provides callbacks related to mouse events. It includes the functions: mouseMoved, mousePressed, and mouseReleased. See OIS for more information on this input library.
  5. An SdkTrayListener is part of the OgreBites sample framework included in every Ogre SDK. It is used to provide GUI events. For more information, you can read through SdkTrays and SdkCameraMan.

How It Works

  1. An Ogre::Root is created.
  2. Resource locations are read from a configuration file.
  3. The Render Settings dialog is shown.
  4. A scene manager is created.
  5. The camera is set up.
  6. The OgreBites camera manager is linked to the camera.
  7. A viewport is created.
  8. All resource groups are initialized.
  9. The scene is built.
  10. OIS is initialized.
  11. The application requests to be registered as an input listener.
  12. The SdkTrays widgets from OgreBites are setup, including debug overlays.
  13. The application registers itself as a frame listener.
  14. The render loop starts.
  15. The application loops until it is quit.

Walkthrough

As a means of walking you through the Ogre Wiki Tutorial Framework, let's see if we can create three alternative frameworks.
These serve to illustrate how the framework works, because the functionality is the same, only organised differently.

MinimalOgre

The biggest complaint about the Ogre Wiki Tutorial Framework could be that all the details are too hidden away. For example TutorialApplication inherits from BaseApplication...it's too oblique. Why not just put everything into one class?

Alright, here's 'MinimalOgre':
MinimalOgre-h
MinimalOgre-cpp
It's identical to the Ogre Wiki Tutorial Framework, but it's only one class, and it has only one function: go().

Take a good look at that function, because it does exactly the same as what the Ogre Wiki Tutorial Framework - and that's it.
Comments indicate what function of the Ogre Wiki Tutorial Framework the code relates to:

bool MinimalOgre::go(void)
{
#ifdef _DEBUG
    mResourcesCfg = "resources_d.cfg";
    mPluginsCfg = "plugins_d.cfg";
#else
    mResourcesCfg = "resources.cfg";
    mPluginsCfg = "plugins.cfg";
#endif
 
    // construct Ogre::Root
    mRoot = new Ogre::Root(mPluginsCfg);
 
//-------------------------------------------------------------------------------------
    // setup resources
    // Load resource paths from config file
    Ogre::ConfigFile cf;
    cf.load(mResourcesCfg);
 
    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
 
    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                archName, typeName, secName);
        }
    }
//-------------------------------------------------------------------------------------
    // configure
    // Show the configuration dialog and initialise the system
    // You can skip this and use root.restoreConfig() to load configuration
    // settings if you were sure there are valid ones saved in ogre.cfg
    if(mRoot->restoreConfig() || mRoot->showConfigDialog())
    {
        // If returned true, user clicked OK so initialise
        // Here we choose to let the system create a default rendering window by passing 'true'
        mWindow = mRoot->initialise(true, "MinimalOgre Render Window");
    }
    else
    {
        return false;
    }
//-------------------------------------------------------------------------------------
    // choose scenemanager
    // Get the SceneManager, in this case a generic one
    mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);
//-------------------------------------------------------------------------------------
	// initialize the OverlaySystem (changed for 1.9)
	mOverlaySystem = new Ogre::OverlaySystem();
    mSceneMgr->addRenderQueueListener(mOverlaySystem);
//-------------------------------------------------------------------------------------
    // create camera
    // Create the camera
    mCamera = mSceneMgr->createCamera("PlayerCam");
 
    // Position it at 500 in Z direction
    mCamera->setPosition(Ogre::Vector3(0,0,80));
    // Look back along -Z
    mCamera->lookAt(Ogre::Vector3(0,0,-300));
    mCamera->setNearClipDistance(5);
 
    mCameraMan = new OgreBites::SdkCameraMan(mCamera);   // create a default camera controller
//-------------------------------------------------------------------------------------
    // create viewports
    // Create one viewport, entire window
    Ogre::Viewport* vp = mWindow->addViewport(mCamera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
 
    // Alter the camera aspect ratio to match the viewport
    mCamera->setAspectRatio(
        Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
//-------------------------------------------------------------------------------------
    // Set default mipmap level (NB some APIs ignore this)
    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
//-------------------------------------------------------------------------------------
    // Create any resource listeners (for loading screens)
    //createResourceListener();
//-------------------------------------------------------------------------------------
    // load resources
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
//-------------------------------------------------------------------------------------
    // Create the scene
    Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
 
    Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
    headNode->attachObject(ogreHead);
 
    // Set ambient light
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
 
    // Create a light
    Ogre::Light* l = mSceneMgr->createLight("MainLight");
    l->setPosition(20,80,50);
//-------------------------------------------------------------------------------------
    //create FrameListener
    Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
    OIS::ParamList pl;
    size_t windowHnd = 0;
    std::ostringstream windowHndStr;
 
    mWindow->getCustomAttribute("WINDOW", &windowHnd);
    windowHndStr << windowHnd;
    pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
 
    mInputManager = OIS::InputManager::createInputSystem( pl );
 
    mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true ));
    mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true ));
 
    mMouse->setEventCallback(this);
    mKeyboard->setEventCallback(this);
 
    //Set initial mouse clipping size
    windowResized(mWindow);
 
    //Register as a Window listener
    Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);
 
    mInputContext.mKeyboard = mKeyboard;
    mInputContext.mMouse = mMouse;
    mTrayMgr = new OgreBites::SdkTrayManager("InterfaceName", mWindow, mInputContext, this);
    mTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
    mTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
    mTrayMgr->hideCursor();
 
    // create a params panel for displaying sample details
    Ogre::StringVector items;
    items.push_back("cam.pX");
    items.push_back("cam.pY");
    items.push_back("cam.pZ");
    items.push_back("");
    items.push_back("cam.oW");
    items.push_back("cam.oX");
    items.push_back("cam.oY");
    items.push_back("cam.oZ");
    items.push_back("");
    items.push_back("Filtering");
    items.push_back("Poly Mode");
 
    mDetailsPanel = mTrayMgr->createParamsPanel(OgreBites::TL_NONE, "DetailsPanel", 200, items);
    mDetailsPanel->setParamValue(9, "Bilinear");
    mDetailsPanel->setParamValue(10, "Solid");
    mDetailsPanel->hide();
 
    mRoot->addFrameListener(this);
//-------------------------------------------------------------------------------------
    mRoot->startRendering();
 
    return true;
}

Well, it does actually have more than one function, but those are overridden listener functions, because Minimal Ogre is still 5 listeners rolled into one.
To keep things simple.

Pros

For use in your own projects, this is probably the way to go as you don't have to worry about whether you should override the functions of the base class in your derived class, or if you should change the functions directly in the base class.
There's generally no need to be subclassing as the framework is copied from project to project.
So let's skip one additional layer of abstraction.

Cons

As a Tutorial Framework, this is not the way to go.
To illustrate different aspects of Ogre, it works better if the common boiler plate code - which is going to be pretty much the same from tutorial to tutorial - is tucked away in a base class.
It's much easier to deal with changes by overriding functions, instead of telling you to modify that piece of code and then some code here and some lines there.
What's good for your own projects is bad for a tutorial framework.
Having everything in one class doesn't help illustrate certain aspects of Ogre programming. The other code 'gets in the way'.

TinyOgre

'It's still too much code! I want less!'
TinyOgre-h
TinyOgre-cpp

Tiny Ogre doesn't inherit anything.
It's not using OIS for input, it doesn't listen to frame events or window events - it's about as scraped as an Ogre application can be:

bool TinyOgre::go(void)
{
#ifdef _DEBUG
    mResourcesCfg = "resources_d.cfg";
    mPluginsCfg = "plugins_d.cfg";
#else
    mResourcesCfg = "resources.cfg";
    mPluginsCfg = "plugins.cfg";
#endif

    // construct Ogre::Root
    mRoot = new Ogre::Root(mPluginsCfg);

//-------------------------------------------------------------------------------------
    // set up resources
    // Load resource paths from config file
    Ogre::ConfigFile cf;
    cf.load(mResourcesCfg);

    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                archName, typeName, secName);
        }
    }
//-------------------------------------------------------------------------------------
    // configure
    // Show the configuration dialog and initialise the system
    // You can skip this and use root.restoreConfig() to load configuration
    // settings if you were sure there are valid ones saved in ogre.cfg
    if(mRoot->restoreConfig() || mRoot->showConfigDialog())
    {
        // If returned true, user clicked OK so initialise
        // Here we choose to let the system create a default rendering window by passing 'true'
        mWindow = mRoot->initialise(true, "TinyOgre Render Window");
    }
    else
    {
        return false;
    }
//-------------------------------------------------------------------------------------
    // choose scenemanager
    // Get the SceneManager, in this case a generic one
    mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);
//-------------------------------------------------------------------------------------
    // create camera
    // Create the camera
    mCamera = mSceneMgr->createCamera("PlayerCam");

    // Position it at 500 in Z direction
    mCamera->setPosition(Ogre::Vector3(0,0,80));
    // Look back along -Z
    mCamera->lookAt(Ogre::Vector3(0,0,-300));
    mCamera->setNearClipDistance(5);

//-------------------------------------------------------------------------------------
    // create viewports
    // Create one viewport, entire window
    Ogre::Viewport* vp = mWindow->addViewport(mCamera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0));

    // Alter the camera aspect ratio to match the viewport
    mCamera->setAspectRatio(
        Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
//-------------------------------------------------------------------------------------
    // Set default mipmap level (NB some APIs ignore this)
    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
//-------------------------------------------------------------------------------------
    // Create any resource listeners (for loading screens)
    //createResourceListener();
//-------------------------------------------------------------------------------------
    // load resources
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
//-------------------------------------------------------------------------------------
    // Create the scene
    Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");

    Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
    headNode->attachObject(ogreHead);

    // Set ambient light
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));

    // Create a light
    Ogre::Light* l = mSceneMgr->createLight("MainLight");
    l->setPosition(20,80,50);
//-------------------------------------------------------------------------------------

    while(true)
    {
        // Pump window messages for nice behaviour
        Ogre::WindowEventUtilities::messagePump();

        if(mWindow->isClosed())
        {
            return false;
        }

        // Render a frame
        if(!mRoot->renderOneFrame()) return false;
    }

    // We should never be able to reach this corner
    // but return true to calm down our compiler
    return true;
}

Please notice that you have to exit the application by closing the window 'manually' - there's no input.

Pros

This code is not going to get in your way. :-)
There's simply too little of it.
As few assumptions as possible.
But: it does illustrate the minimum amount of code required to get Ogre up and rendering.

Cons

It does almost nothing, so you need to hook it up with input, listeners, etc.
This is not suited for a tutorial framework as there would be too much repetition.

LowLevelOgre

'I think you're hiding too much by relying on configuration files!'

You're right: 'resources.cfg', 'plugins.cfg' and 'ogre.cfg' are not really a part of Ogre.
It's an Ogre Samples convenience thing.
We can do this in code:
LowLevelOgre-h
LowLevelOgre-cpp

Setup

This piece of code constructs a new Ogre::Root, telling it to not use any plugins or config files, because we'll be setting it up in code.

// construct Ogre::Root : no plugins filename, no config filename, using a custom log filename
mRoot = new Ogre::Root("", "", "LowLevelOgre.log");

// A list of required plugins
Ogre::StringVector required_plugins;
required_plugins.push_back("GL RenderSystem");
required_plugins.push_back("Octree & Terrain Scene Manager");

// List of plugins to load
Ogre::StringVector plugins_toLoad;
plugins_toLoad.push_back("RenderSystem_GL");
plugins_toLoad.push_back("Plugin_OctreeSceneManager");

// Load the OpenGL RenderSystem and the Octree SceneManager plugins
for (Ogre::StringVector::iterator j = plugins_toLoad.begin(); j != plugins_toLoad.end(); j++)
{
#ifdef _DEBUG
    mRoot->loadPlugin(*j + Ogre::String("_d"));
#else
    mRoot->loadPlugin(*j);
#endif;
}

// Check if the required plugins are installed and ready for use
// If not: exit the application
Ogre::Root::PluginInstanceList ip = mRoot->getInstalledPlugins();
for (Ogre::StringVector::iterator j = required_plugins.begin(); j != required_plugins.end(); j++)
{
    bool found = false;
    // try to find the required plugin in the current installed plugins
    for (Ogre::Root::PluginInstanceList::iterator k = ip.begin(); k != ip.end(); k++)
    {
        if ((*k)->getName() == *j)
        {
            found = true;
            break;
        }
    }
    if (!found)  // return false because a required plugin is not available
    {
        return false;
    }
}

One additional bonus feature of this code is that it checks the loaded plugins against the required list of plugins and exits if a required plugin is missing.

Here's a list of the plugin names and the render system names:

BSPSceneManager PluginName = "BSP Scene Manager"
OgreCgPlugin PluginName = "Cg Program Manager"
OgreOctreePlugin PluginName = "Octree & Terrain Scene Manager"
OctreeZone PluginName = "Octree Zone Factory"
OgreParticleFXPlugin PluginName = "ParticleFX"
PCZSceneManager PluginName = "Portal Connected Zone Scene Manager"
Direct3D10 PluginName = "D3D10 RenderSystem"
OgreD3D11Plugin PluginName = "D3D11 RenderSystem"
OgreD3D9Plugin PluginName = "D3D9 RenderSystem"
OgreGLPlugin PluginName = "GL RenderSystem"
OgreGLESPlugin PluginName = "OpenGL ES 1.x RenderSystem"

OgreD3D10RenderSystem Name = "Direct3D10 Rendering Subsystem"
Direct3D11 Name = "Direct3D11 Rendering Subsystem"
Direct3D9 Name = "Direct3D9 Rendering Subsystem"
GL Name = "OpenGL Rendering Subsystem"
GLES Name = "OpenGL ES 1.x Rendering Subsystem"


In later builds of OGRE the Octree plugin name has been changed in 2010 (1.7+) to no longer incorporate the Terrain element.

OgreOctreePlugin PluginName = "Octree Scene Manager"

Resources

This one is almost too easy to do in code:

// setup resources
// Only add the minimally required resource locations to load up the Ogre head mesh
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/programs", "FileSystem", "General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/scripts", "FileSystem", "General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/textures", "FileSystem", "General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/models", "FileSystem", "General");

Configure

We have hardcoded ourselves to using the OpenGL Rendering Subsystem, with a windowed mode in 800x600 resolution with vsync turned off:

// configure
// Grab the OpenGL RenderSystem, or exit
Ogre::RenderSystem* rs = mRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
if(!(rs->getName() == "OpenGL Rendering Subsystem"))
{
    return false; //No RenderSystem found
}
// configure our RenderSystem
rs->setConfigOption("Full Screen", "No");
rs->setConfigOption("VSync", "No");
rs->setConfigOption("Video Mode", "800 x 600 @ 32-bit");

mRoot->setRenderSystem(rs);

mWindow = mRoot->initialise(true, "LowLevelOgre Render Window");

Pros

It's much clearer what's happening as there isn't an additional layer of logic.
Nothing is fetched from the outside.

Cons

Each and every change requires you to change the code and recompile.
It's literally hard-coded.

The Framework

Pros and Cons of the Ogre Wiki Tutorial Framework.

Pros

The modularity of the framework - base class, derived class - makes it obvious what is changed/customised.
It's also easier to walk through as it's neatly organised in touched (overridden) functions and un-touched functions.

Cons

If you're not careful, you won't see the tucked away code (much).
Hopefully, the progression of the Ogre Tutorials will make sure that you get around all corners of the small framework.

Conclusion

You are still thinking to yourself:
'Why are you hiding so much functionality'?

The answer is:
Ogre is abstracting away those nitty gritty details so you don't have to worry about them.

If you really want to learn the low level basics of 3D programming, look into nitty OpenGL and/or gritty DirectX.

Honest. :-)

The tutorial framework is not really hiding anything not already hidden by Ogre itself.

Sure, you can do some tricks using some lower level Ogre API, but that is something for the intermediate tutorials, in-depth articles and the snippets.

Geek Alert
geek.gif


It's a good idea to study Ogre::Root!
It's a façade class, which means that everything Ogre::Root does, you can do yourself.
Ogre::Root is more or less a convenience class which does some housekeeping for you.

The Files

The Downloads

Ogre Wiki Tutorial Framework

For Ogre 1.9 ("Ghadamon")

 Plugin disabled
Plugin attach cannot be executed.
 Plugin disabled
Plugin attach cannot be executed.

For Ogre 1.10 ("Xalafu")

 Plugin disabled
Plugin attach cannot be executed.
 Plugin disabled
Plugin attach cannot be executed.

Minimal Ogre

 Plugin disabled
Plugin attach cannot be executed.
 Plugin disabled
Plugin attach cannot be executed.

Tiny Ogre

 Plugin disabled
Plugin attach cannot be executed.
 Plugin disabled
Plugin attach cannot be executed.

Low Level Ogre

 Plugin disabled
Plugin attach cannot be executed.
 Plugin disabled
Plugin attach cannot be executed.