[Solved] TrayManager not working

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
saintnick
Halfling
Posts: 51
Joined: Tue Nov 27, 2018 1:41 am
x 2

[Solved] TrayManager not working

Post by saintnick » Tue Nov 27, 2018 1:56 am

Ogre Version: latest source
Operating System: Windows 10
Render System: Any/all

I've built Ogre3d from source. I have also done BasicTutorial1.cpp and BasicTutorial2.cpp with good results. I have spent a few hours trying to figure out why I can't display anything with Trays GUI system. I am working from this https://ogrecave.github.io/ogre/api/1.1 ... raymanager tutorial. Searching the forums came up with this thread viewtopic.php?t=94386. At the bottom of this thread someone posted to add

Code: Select all

scnMgr->addRenderQueueListener(mOverlaySystem);
Using this code gave me the error "argument of type "OgreBites::TrayManager *" is incompatible with parameter of type "Ogre::RenderQueueListener *""

Any ideas why the following code doesn't show a button?

Code: Select all

	ApplicationContext::setup();
	addInputListener(this);

	Root* root = getRoot();
	SceneManager* scnMgr = root->createSceneManager();
	SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();

	Camera* cam = scnMgr->createCamera("myCam");
	cam->setNearClipDistance(5);
	cam->setAutoAspectRatio(true);
	camNode->attachObject(cam);
	camNode->setPosition(0, 0, 140);

	Viewport* vp = getRenderWindow()->addViewport(cam);
	vp->setBackgroundColour(ColourValue(0, 0, 0));
	cam->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
	
	mOverlaySystem = new TrayManager("InterfaceName", getRenderWindow(), this);
	mOverlaySystem->showLogo(TL_RIGHT);
	Button* b = mOverlaySystem->createButton(TL_BOTTOMLEFT, "MyButton", "Click Me!");
Last edited by saintnick on Wed Dec 19, 2018 2:55 pm, edited 1 time in total.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 878
Joined: Sun Mar 30, 2014 2:51 pm
x 177
Contact:

Re: TrayManager not working

Post by paroj » Tue Nov 27, 2018 10:37 am

0 x

User avatar
saintnick
Halfling
Posts: 51
Joined: Tue Nov 27, 2018 1:41 am
x 2

Re: TrayManager not working

Post by saintnick » Tue Nov 27, 2018 2:26 pm

Thank you. I didn't realize I was using an old version of the documentation. The python example also helped. TrayManager was working all along.

The following code now shows the button and logo!

Code: Select all

	mTrayMgr = new TrayManager("InterfaceName", getRenderWindow());
	scnMgr->addRenderQueueListener(getOverlaySystem());
	mTrayMgr->showLogo(TL_RIGHT);
	Button* b = mTrayMgr->createButton(TL_BOTTOMLEFT, "MyButton", "Click Me!");
The tutorial says to destroy the TrayManager like so

Code: Select all

delete mTrayMgr;
This causes my application to throw the following error at close:

Code: Select all

Assertion failure!
Program: OgreOverlay_d.dll
File: OgreOverlayManager.cpp line 50
Expression: msSingleton
I removed this from my BasicTutorials destructor and the program runs fine without errors.
0 x

User avatar
saintnick
Halfling
Posts: 51
Joined: Tue Nov 27, 2018 1:41 am
x 2

TrayManager now working

Post by saintnick » Wed Nov 28, 2018 12:21 am

Thank you for your help.

Just wanted to update this for other Ogre3D users who search the forum about TrayManager.

The following code listing shows my implementation.

Code: Select all

// create gui interface
	mTrayMgr = new TrayManager("InterfaceName", getRenderWindow());
// without this your gui will not display
	scnMgr->addRenderQueueListener(getOverlaySystem());
// without this your buttonHit function will not be called
	mTrayMgr->setListener(this);
// show the logo and create a button
	mTrayMgr->showLogo(TL_RIGHT);
	Button* play = mTrayMgr->createButton(TL_BOTTOMLEFT, "quitButton", "Quit");

Code: Select all

void BasicTutorial::buttonHit(Button* b)
{
	if (b->getName() == "quitButton")
	{
		getRoot()->queueEndRendering();
	}
}
You will also need these methods.

Code: Select all

bool BasicTutorial::mousePressed(const MouseButtonEvent& evt)
{
	if (mTrayMgr->mousePressed(evt)) return true;
	/* normal mouse processing here... */
	return true;
}

bool BasicTutorial::mouseReleased(const MouseButtonEvent& evt)
{
	if (mTrayMgr->mouseReleased(evt)) return true;
	/* normal mouse processing here... */
	return true;
}

bool BasicTutorial::mouseMoved(const MouseMotionEvent& evt)
{
	if (mTrayMgr->mouseMoved(evt)) return true;
	/* normal mouse processing here... */
	return true;
}

bool BasicTutorial::keyPressed(const KeyboardEvent& evt)
{
	if (evt.keysym.sym == SDLK_ESCAPE)
	{
		getRoot()->queueEndRendering();
	}
}
This creates a window with a quit button that once pressed closes the window.

I also created a cleanUp method that calls delete mTrayMgr as recommended in the tutorials.

Code: Select all

void BasicTutorial::cleanUp()
{
	delete mTrayMgr;
}
I then call that in my main function as so.

Code: Select all

		BasicTutorial1 app;
		app.initApp();
		app.getRoot()->startRendering();
		app.cleanUp();
		app.closeApp();
}
This gets rid of the assertion error I had when I put delete mTrayMgr in the destructor for BasicTutorial1.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 878
Joined: Sun Mar 30, 2014 2:51 pm
x 177
Contact:

Re: TrayManager not working

Post by paroj » Wed Nov 28, 2018 11:59 am

you rater should overload shutdown() for cleanup tasks as done in the python sample
0 x

User avatar
saintnick
Halfling
Posts: 51
Joined: Tue Nov 27, 2018 1:41 am
x 2

CameraMan

Post by saintnick » Thu Nov 29, 2018 7:13 pm

I fixed that shutdown overload.

Code: Select all

void BasicTutorial::shutdown()
{
	delete mTrayMgr;
	delete mCameraMan;
}
Thank you.

I am not sure if I should create a new thread but I ran into another issue not related to the TrayManager.

I have added CameraMan to my project and can now look and move around.

My issue comes from when I try to look around. The camera stops moving around when the cursor hits the edge of the window. This differs from some of the samples such as BSP and Terrain. In those the camera rotates around if you keep moving the mouse.

I have looked at the source code for BSP and Terrain and tried to figure out what they do differently than my project. I am stumped.

Here is a code listing.

Code: Select all

	Light* light = scnMgr->createLight("MainLight");
	SceneNode* lightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
	lightNode->setPosition(0, 10, 15);
	lightNode->attachObject(light);

	Entity* sinbad = scnMgr->createEntity("Sinbad.mesh");
	SceneNode* node = scnMgr->getRootSceneNode()->createChildSceneNode();
	node->attachObject(sinbad);

Code: Select all

	mCameraMan = new CameraMan(camNode);   // create a default camera controller
	mCameraMan->setStyle(CS_FREELOOK);
	mCameraMan->setTopSpeed(350);   // make the camera move a bit faster

Code: Select all

bool BasicTutorial::mouseMoved(const MouseButtonEvent& evt)
{
	if (mTrayMgr->mouseMoved(evt)) return true;
	mCameraMan->mouseMoved(evt);
	return true;
}
I can approach Sinbad but when I try to do a 360 degree turn the camera stops looking once I hit the edge of my window. Happens in full screen and windowed.
0 x

User avatar
saintnick
Halfling
Posts: 51
Joined: Tue Nov 27, 2018 1:41 am
x 2

Re: TrayManager not working

Post by saintnick » Sat Dec 01, 2018 4:16 am

This line of code fixed the behavior of my camera.

Code: Select all

SDL_SetRelativeMouseMode(SDL_TRUE);
When the mouse reaches the edge of the window the camera continues to rotate while the mouse is moving instead of stopping.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 878
Joined: Sun Mar 30, 2014 2:51 pm
x 177
Contact:

Re: TrayManager not working

Post by paroj » Sat Dec 01, 2018 1:20 pm

the recommended way for this is to use:
https://ogrecave.github.io/ogre/api/lat ... caafd38503
0 x

Post Reply