Time for action — adding a FrameListener

Using the code from before we are going to add our own FrameListener implementation

  1. Create a new class called MyFrameListener exposing three publicly visible event handler functions:
    class MyFrameListener : public Ogre::FrameListener
    {
    public:
    
  2. First, implement the frameStarted function, which for now returns false to close the application:
    bool frameStarted(const Ogre::FrameEvent& evt)
    {
    return false;
    }
    
  3. We also need a frameEnded function, which also returns false:
    bool frameEnded(const Ogre::FrameEvent& evt)
    {
    return false;
    }
    
  4. The last function we implement is the frameRenderingQueued function, which also returns false:
    bool frameRenderingQueued(const Ogre::FrameEvent& evt)
    {
    return false;
    }
    
  5. The main class needs a point to store the FrameListener:
    MyFrameListener* _listener;
    
  6. Remember that the constructor needs to set the initial value of the listener to NULL:
    _listener = NULL;
    
  7. Let the destructor delete the instance:
    delete _listener;
    
  8. At last, create a new instance of the FrameListener and add it to the root object; this should happen in the startup() function:
    _listener = new MyFrameListener();
    _root->addFrameListener(_listener);
    
  9. Compile and run the application; it should be closed directly.

What just happened?

We created our own FrameListener class, which didn't rely on the ExampleFrameListener implementation. This time we inherited directly from the FrameListener interface. This interface consists of three virtual functions, which we implemented. We already knew the frameStarted function, but the other two are new. All three functions return false, which is an indicator to Ogre 3D to stop rendering and close the application. Using our implementation, we added a FrameListener to the root instance and started the application; not surprisingly, it closed directly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.42.129