Skip to content

Commit

Permalink
Docs: Tutorials - simplify the boostrap code
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Sep 24, 2022
1 parent 58f0f98 commit 3a3163d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 52 deletions.
26 changes: 10 additions & 16 deletions Docs/src/tutorials/setup.md
Expand Up @@ -27,36 +27,30 @@ The easiest way to get started is the OgreBites Component. It handles Ogre start
This is useful if all you want is to get a Scene with a FPS counter up and running (rapid prototyping).
If available it also uses SDL2 for input - you now just have to implement the callbacks.

To use it, simply derive from OgreBites::ApplicationContext and if you want to get input events from OgreBites::InputListener

```cpp
class MyTestApp : public OgreBites::ApplicationContext, public OgreBites::InputListener
{
...
}
```
in the constructor we set our application name. The ogre configuration files will be stored in a system dependent location specific to our app.
The main class is OgreBites::ApplicationContext which manages the lifetime of everything else.
In the constructor we set our application name. The ogre configuration files will be stored in a system dependent location specific to our app. Then @c initApp will initialise all components and create a window for us.
@snippet Samples/Tutorials/Bootstrap.cpp constructor

to handle input events, we then override the according method
@snippet Samples/Tutorials/Bootstrap.cpp key_handler
the interesting part however is the setup method
the interesting part however is creation of the actual scene
@note The code is explained in detail in the Tutorial @ref tut_FirstScene

@snippet Samples/Tutorials/Bootstrap.cpp setup

to handle input events, we then override the according method
@snippet Samples/Tutorials/Bootstrap.cpp key_handler

finally we start everything as
@snippet Samples/Tutorials/Bootstrap.cpp main

OgreBites itself is also a good starting point if you need more control over the Camera or the Window creation.
For instance to render into an externally created Window. Fore Qt interop, there is OgreBites::ApplicationContextQt.

@note You can find the full code of the above example at
* `Samples/Tutorials/Bootstrap.cpp` for C++
* `Samples/Python/sample.py` for Python
* `Samples/AndroidJNI/MainActivity.java` for Java (Android)
* `Samples/Csharp/example.cs` for C\#

OgreBites itself is also a good starting point if you need more control over the Camera or the Window creation.
For instance to render into an existing Qt Window.
@see Ogre::FileSystemLayer::getConfigFilePath
@see Ogre::Root::renderOneFrame
@see Ogre::RenderSystem::_createRenderWindow
Expand Down
59 changes: 23 additions & 36 deletions Samples/Tutorials/Bootstrap.cpp
Expand Up @@ -6,42 +6,30 @@
#include "Ogre.h"
#include "OgreApplicationContext.h"

class MyTestApp : public OgreBites::ApplicationContext, public OgreBites::InputListener
{
public:
MyTestApp();
void setup();
bool keyPressed(const OgreBites::KeyboardEvent& evt);
};

//! [constructor]
MyTestApp::MyTestApp() : OgreBites::ApplicationContext("OgreTutorialApp")
{
}
//! [constructor]

//! [key_handler]
bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt)
class KeyHandler : public OgreBites::InputListener
{
if (evt.keysym.sym == OgreBites::SDLK_ESCAPE)
bool keyPressed(const OgreBites::KeyboardEvent& evt) override
{
getRoot()->queueEndRendering();
if (evt.keysym.sym == OgreBites::SDLK_ESCAPE)
{
Ogre::Root::getSingleton().queueEndRendering();
}
return true;
}
return true;
}
};
//! [key_handler]

//! [setup]
void MyTestApp::setup(void)
int main(int argc, char *argv[])
{
// do not forget to call the base first
OgreBites::ApplicationContext::setup();

// register for input events
addInputListener(this);
//! [constructor]
OgreBites::ApplicationContext ctx("OgreTutorialApp");
ctx.initApp();
//! [constructor]

//! [setup]
// get a pointer to the already created root
Ogre::Root* root = getRoot();
Ogre::Root* root = ctx.getRoot();
Ogre::SceneManager* scnMgr = root->createSceneManager();

// register our scene with the RTSS
Expand All @@ -66,22 +54,21 @@ void MyTestApp::setup(void)
camNode->attachObject(cam);

// and tell it to render into the main window
getRenderWindow()->addViewport(cam);
ctx.getRenderWindow()->addViewport(cam);

// finally something to render
Ogre::Entity* ent = scnMgr->createEntity("Sinbad.mesh");
Ogre::SceneNode* node = scnMgr->getRootSceneNode()->createChildSceneNode();
node->attachObject(ent);
}
//! [setup]

//! [main]
int main(int argc, char *argv[])
{
MyTestApp app;
app.initApp();
app.getRoot()->startRendering();
app.closeApp();
// register for input events
KeyHandler keyHandler;
ctx.addInputListener(&keyHandler);

ctx.getRoot()->startRendering();
ctx.closeApp();
//! [main]
return 0;
}
//! [main]

0 comments on commit 3a3163d

Please sign in to comment.