NoesisGUI

OGRE Integration Tutorial

Steps needed to render user interfaces using NoesisGUI on OGRE are described in this tutorial. With each distribution of NoesisGUI you can find a package that contains an API to use NoesisGUI on your OGRE projects and a sample application (whose screenshoot is shown below).

Before using any XAML file in your OGRE project it must be built with the command line tool BuildTool as described in the following tutorial. This tool is distributed with the SDK of NoesisGUI. Having built the resources and checked that they render properly on XamlPlayer you must copy them to your ogre project. Copy the /Bin/Data/ folder from your NoesisSDK distribution to the folder /media/NoesisGUI of your OGRE project.

At initialization time Noesis_Init() is invoked and the desired XAML is loaded:

// Setup NsGui
Noesis_Init(mSceneMgr);
Noesis_LoadXAML(&mUIRoot, &mUIRenderer, "Gui/TicTacToe/MainWindow.xaml");
Noesis_RendererClearMode(mUIRenderer, 1); // Manual
Noesis_RendererAntialiasingMode(mUIRenderer, 1); // PAA

Input events are passed down to NoesisGUI as shown in the following code snippet:

bool Sample::keyPressed(const OIS::KeyEvent &e)
{
    if (e.key == OIS::KC_ESCAPE)
    {
        mExitMainLoop = true;
        return true;
    }
    Noesis_KeyDown(mUIRenderer, e.key);
    Noesis_Char(mUIRenderer, e.text);
    return false;
}

bool Sample::keyReleased(const OIS::KeyEvent &e)
{
    Noesis_KeyUp(mUIRenderer, e.key);
    return false;
}

bool Sample::mouseMoved(const OIS::MouseEvent &e)
{
    Noesis_MouseMove(mUIRenderer, (float)e.state.X.abs, (float)e.state.Y.abs);
    Noesis_MouseWheel(mUIRenderer, (float)e.state.X.abs, (float)e.state.Y.abs, e.state.Z.abs);
    return false;
}

bool Sample::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
    Noesis_MouseButtonDown(mUIRenderer, (float)e.state.X.abs, (float)e.state.Y.abs, id);
    return false;
}

bool Sample::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
    Noesis_MouseButtonUp(mUIRenderer, (float)e.state.X.abs, (float)e.state.Y.abs, id);
    return false;
}

Having finished the setup the renderer must be ticked on each frame:

Noesis_Tick();
Noesis_UpdateRenderer(mUIRenderer, ((double)mRoot->getTimer()->getMilliseconds() / 1000.0));

To receive events from the GUI the desired element must be found using the FindName() function. The event is registered using delegates:

mBoardPanel = NsStaticCast<FrameworkElement*>(mRoot->FindName("Board"));
NS_ASSERT(mBoardPanel);
mBoardPanel->MouseLeftButtonDown() += MakeDelegate(this, &TicTacToeLogic::BoardClicked);

And those are the basic steps. Of course there are details that are not shown here. To see a real working example it is recommended that you download the mentioned package and study the provided source code.

Ogre3DTutorialImg1.png
© 2017 Noesis Technologies