[Solved!] wxWidgets 3.0.1, ogre1.9.0 and overlays

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
paulosherring
Gnoblar
Posts: 4
Joined: Mon Sep 03, 2012 11:04 pm

[Solved!] wxWidgets 3.0.1, ogre1.9.0 and overlays

Post by paulosherring »

Hello all!
I am coding a small software which the main framework is wxWidgets. Before, I used wxwidgets 2.9.4, VS2010 and ogre 1.7.2 and everything ran smooth. I went on formating my PC and decided to upgrade my IDE and whole components and now I am using VS2012, wxWidgets 3.0.1 and ogre 1.9.0. I can compile and all my previus code worked well, the only error i found was due to overlay component was moved out from ogre. Besides that, no errors on compile time.
On run time, i could not get my custom sdktrays to work (the only thing is that I striped OIS stuff and lean'd it, resuming it to params panel and other information stuff). I tried then a simple application and no sdktrays at all, only simple overlay white square and still nothing appeared.
I ask you:
Am I doing something wrong here?
Is there any know bug concerning this?

The code is bellow.
Thanks in advance!
Paulo Sherring.
main.cpp:

Code: Select all

#include "main.h"
#ifndef WX_PRECOMP
	#include <wx/wx.h>
#else
	#include <wx/wxprec.h>
#endif
#include <vld.h>
wxLocale * m_locale;
IMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
	m_locale = new wxLocale();
	m_locale->Init(wxLanguage::wxLANGUAGE_ENGLISH);
	if ( !wxApp::OnInit() )
        return false;
	wxInitAllImageHandlers();
	mainFrame = new wxfMainFrame(NULL,wxID_ANY,wxString("Main Window"));	
	mainFrame->Centre();
	mainFrame->Maximize();
	mainFrame->Show();
	return true;
}

int MyApp::OnExit()
{
	m_locale->DestroyLanguagesDB();
	delete m_locale;
	return 0;
}

wxfMainFrame::wxfMainFrame(wxWindow *parent, wxWindowID id, const wxString& title) :
	wxFrame(parent,id,title)
{
#ifdef _DEBUG
	Ogre::String mPluginCfg = "plugins_d.cfg";
#else
	Ogre::String mPluginCfg = "plugins.cfg";
#endif
	mRoot = Ogre::Root::getSingletonPtr();
	if (!mRoot) {
		mRoot = new Ogre::Root(mPluginCfg); 
	}
	mRoot->restoreConfig();
	mSceneMgr = mRoot->createSceneManager("DefaultSceneManager");
	mOverlaySys = new Ogre::OverlaySystem();

	#ifdef _DEBUG
	Ogre::String mResourcesCfg = "resources_d.cfg";
#else
	Ogre::String mResourcesCfg = "resources.cfg";
#endif
	Ogre::ConfigFile cf;
	cf.load(mResourcesCfg);

	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
 	Ogre::String secName, typeName, archName;
	while (seci.hasMoreElements())
	{
		secName = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
		Ogre::ConfigFile::SettingsMultiMap::iterator i;
		for (i = settings->begin(); i != settings->end(); ++i)
		{
			typeName = i->first;
			archName = i->second;
			Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
		}
	}
	try{
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
	} catch (std::exception& e)
	{
		MessageBoxA(0,e.what(),"Erro",MB_OK);
	};
	mRenderWindow = new wxOgreRenderWindow(this,wxID_ANY);
	mRenderWindow->createRenderWindow();
	// Cria uma Câmera
	mCamera = mSceneMgr->createCamera("CameraLivre");
	mCamera->setPosition(Ogre::Vector3(170,500,1000));
	mCamera->lookAt(Ogre::Vector3(170,250,0));
	mCamera->setNearClipDistance(5);
	// Cria um Viewport, de tela inteira
	mViewPort = mRenderWindow->getRenderWindow()->addViewport(mCamera);
	mViewPort->setBackgroundColour(Ogre::ColourValue(0,0,0));
	// Altera a razão para combinar com o viewport
	mCamera->setAspectRatio(Ogre::Real(mViewPort->getActualWidth()) / Ogre::Real(mViewPort->getActualHeight()));

	Ogre::Light* light = mSceneMgr->createLight( "MainLight" );
	light->setPosition(20, 80, 50);

	Ogre::Entity * ent = mSceneMgr->createEntity("Corpo01Model", "cp01.mesh", "P1");
	Ogre::SceneNode * sn =  mSceneMgr->getRootSceneNode()->createChildSceneNode();
	sn->attachObject(ent);
	
	Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton();
    // Create an overlay
    Ogre::Overlay* overlay = overlayManager.create( "OverlayName" );
	overlay->setZOrder(500);
    // Create a panel
    Ogre::OverlayContainer* panel = static_cast<Ogre::OverlayContainer*>( overlayManager.createOverlayElement( "Panel", "PanelName" ) );
    panel->setPosition( 0.0, 0.0 );
    panel->setDimensions( 0.5, 0.5 );
    panel->setMaterialName( "BaseWhite" );
    // Add the panel to the overlay
    overlay->add2D( panel );
	panel->show();
    // Show the overlay
    overlay->show();
	
	mRenderWindow->setRenderTimerPeriod(50,true);
	mRenderWindow->callRenderFrameOnTimer(true);

}
main.h:

Code: Select all

#pragma once
#ifndef _MAIN_H_
#define _MAIN_H_

#include <wx\wx.h>
#include <Ogre.h>
#include <Overlay\OgreOverlaySystem.h>

#include <wxOgreRenderWindow.h>


class wxfMainFrame;


class MyApp: public wxApp
{
public:
    virtual bool OnInit();
	virtual int OnExit();
	
	wxfMainFrame * mainFrame;
};

DECLARE_APP(MyApp);

class wxfMainFrame : public wxFrame
{
public: 
	wxfMainFrame(wxWindow *parent,
				wxWindowID id,
				const wxString& title) ;
	~wxfMainFrame() {};

	Ogre::Root * mRoot;
	Ogre::SceneManager* mSceneMgr;
	Ogre::OverlaySystem *mOverlaySys;
	Ogre::Camera * mCamera;
	Ogre::Viewport *mViewPort;
	wxOgreRenderWindow * mRenderWindow;

	std::vector< Ogre::Entity * > vecPtrEntidades;
	std::vector< Ogre::SceneNode *> vecPtrSceneNodes;
};

#endif
Last edited by paulosherring on Sat Oct 11, 2014 6:46 am, edited 1 time in total.
NotCamelCase
Greenskin
Posts: 140
Joined: Sun Feb 03, 2013 6:32 pm
x 8

Re: wxWidgets 3.0.1, ogre1.9.0 and overlays

Post by NotCamelCase »

As Singleton classes in Ogre need to be new'd before using, I think new Ogre::OverlayManager() or like will do the trick before you call any getSingleton() or similar function.
Check out my projects: https://github.com/NotCamelCase
paulosherring
Gnoblar
Posts: 4
Joined: Mon Sep 03, 2012 11:04 pm

Re: wxWidgets 3.0.1, ogre1.9.0 and overlays

Post by paulosherring »

I tried it. I guess new Ogre::OverlaySystem(); starts all components, because when i try to instantiate another OverlayManager, with new Ogre::OverlayManager(), an exception is thrown. Likewise, if I instantiate OverlayManager and then OverlaySystem, i get an exception in the later. So, probably is not it.
Thank you, though!
Paulo Sherring.
paulosherring
Gnoblar
Posts: 4
Joined: Mon Sep 03, 2012 11:04 pm

Re: wxWidgets 3.0.1, ogre1.9.0 and overlays

Post by paulosherring »

I just figured it out! All I needed to do is to register OverlaySystem as a RenderQueueListener, by doing, in my case:

Code: Select all

	mOverlaySys = new Ogre::OverlaySystem();
	mSceneMgr = mRoot->createSceneManager("DefaultSceneManager");
	mSceneMgr->addRenderQueueListener(mOverlaySys);
Thanks!!
Post Reply