Ogre's Example Reference Application Layer

Ogre3D provides a Reference Application Layer, that implements most of the code required for initializing Ogre and allows sub-classing and function overriding to replace specific functionality.

Two of the more relevant classes are the ExampleRefAppApplication and the ExampleRefAppFrameListener.

ExampleRefAppApplication is responsible for most of the initialization code, including the following methods (simplified code):

virtual void go(void)
{
    if (setup())
        mRoot->startRendering();
}
 
virtual bool setup(void)
{
    mRoot = new Root();        // creates the root object
    setupResources();          // loads "resources.cfg", a file with paths to resources
    configure();               // shows a dialog box to configure resolution, renderer (OpenGL/DirectX) and other basic settings. Stores in ogre.cfg
    chooseSceneManager();      // creates a generic scene manager
    createWorld();             // Creates a World object, with collision, associated to the scene manager
    createCamera();            // Creates a camera with collision, named "PlayerCam", and places it in the world
    createViewports();         // creates a single viewport occupying the whole window
    createResourceListener();  // empty, to be used if you want to be notified when specific resources are loaded (e.g. to create a "Loading ..." screen
    loadResources();           // Loads all the resources it finds in the paths specified in the "resources.cfg" file
    createScene();             // empty, to be overridden. It is where all geometry should be added
    createFrameListener();     // Creates a default frame listener and adds it to the list of active frame listeners (see below)
}

All the methods called in setup are virtual and may be overridden. However, most of them may be used as they are. Common methods to override are the following:

  • configure: usually overriden to avoid the dialog box
  • createScene: this must be overriden, and should contain the scene creation code; here you can include, among other things, Collidable objects provided by the ExampleRefAppLayer (see below)
  • createFrameListener: this one should be overridden to add additional frame listeners for adding per-frame functionality such as updating a given character; the default frame listener, ExampleRefAppFrameListener, processes user input and moves the player's camera. You can keep this and add other frame listeners, you can create and use a sub-class of ExampleRefAppFrameListener, or replace it altogether with your own class, as long as it implements Ogre::FrameListener.

Collidable Objects

The Reference App Layer includes physics handling based on ODE, and provides a set of basic objects that can be used as base for a physics based game. These objects descend from ApplicationObject and include:

  • Ball
  • Box
  • Plane (one-sided)
  • CollideCamera
  • OgreHead
  • Joint

Other objects may be added by sub-classing ApplicationObject and providing the necessary methods

For an example on how to use the ExampleRefAppLayer, check out Ogre Tutorial 1: Creating a sample application