That's what I did but it did not work. That's why I did derive OgreWidget from QMdiSubWidget.
main.cpp :
#include "OgreMainWindow.h"
#include <QtGui>
int main(int argc, char *argv[])
{
OgreMainWindow w;
w.show();
return a.exec();
}
#include "OgreMainWindow.h"
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
OgreMainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
OgreMainWindow.h :
#ifndef OgreMainWindow_H
#define OgreMainWindow_H
#include <QtGui>
#include "OgreApplication.h"
{
Q_OBJECT
public:
OgreMainWindow
(QWidget *parent
= 0, Qt
::WFlags flags
= 0);
~OgreMainWindow();
public slots:
void createOgreWidget();
private:
QMdiArea * mdiArea;
OgreApplication * ogreApp;
};
#endif // OgreMainWindow_H
#ifndef OgreMainWindow_H
#define OgreMainWindow_H
#include <QtGui>
#include "OgreApplication.h"
class OgreMainWindow : public QMainWindow
{
Q_OBJECT
public:
OgreMainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
~OgreMainWindow();
public slots:
void createOgreWidget();
private:
QMdiArea * mdiArea;
OgreApplication * ogreApp;
};
#endif // OgreMainWindow_H
To copy to clipboard, switch view to plain text mode
OgreMainWindow.cpp :
#include "OgreMainWindow.h"
OgreMainWindow
::OgreMainWindow(QWidget *parent, Qt
::WFlags flags
){
mdiArea = new QMdiArea;
setCentralWidget(mdiArea);
ogreApp = new OgreApplication;
QMenu * menuOgre
= this
->menuBar
()->addMenu
("Ogre");
QAction * ogreInitAction
= menuOgre
->addAction
("Initialise");
QObject::connect( ogreInitAction,
SIGNAL(triggered
()), ogreApp,
SLOT(initialise
()) );
QAction * ogreWidgetAction
= menuOgre
->addAction
("Create Ogre Widget");
QObject::connect( ogreWidgetAction,
SIGNAL(triggered
()),
this,
SLOT(createOgreWidget
()) );
}
OgreMainWindow::~OgreMainWindow()
{
}
void OgreMainWindow::createOgreWidget()
{
OgreWidget * og = ogreApp->createOgreWidget();
mdiArea->addSubWindow( (QMdiSubWindow*)og );
//og->show();
}
#include "OgreMainWindow.h"
OgreMainWindow::OgreMainWindow(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
mdiArea = new QMdiArea;
setCentralWidget(mdiArea);
ogreApp = new OgreApplication;
QMenu * menuOgre = this->menuBar()->addMenu("Ogre");
QAction * ogreInitAction = menuOgre->addAction("Initialise");
QObject::connect( ogreInitAction, SIGNAL(triggered()), ogreApp, SLOT(initialise()) );
QAction * ogreWidgetAction = menuOgre->addAction("Create Ogre Widget");
QObject::connect( ogreWidgetAction, SIGNAL(triggered()), this, SLOT(createOgreWidget()) );
}
OgreMainWindow::~OgreMainWindow()
{
}
void OgreMainWindow::createOgreWidget()
{
OgreWidget * og = ogreApp->createOgreWidget();
mdiArea->addSubWindow( (QMdiSubWindow*)og );
//og->show();
}
To copy to clipboard, switch view to plain text mode
OgreApplication.h :
#ifndef OGREAPPLICATION_H
#define OGREAPPLICATION_H
#include <QObject>
#include <Ogre.h>
class CNahGui;
class OgreWidget;
class OgreApplication
: public QObject{
Q_OBJECT
public:
OgreApplication
(QObject *parent
= 0);
~OgreApplication();
void setupNLoadResources();
void createScene();
public slots:
void initialise();
OgreWidget * createOgreWidget();
private:
Ogre::Root *ogreRoot;
Ogre::SceneManager *ogreSceneManager;
static int nbRenderWindows;
};
#endif // OGREAPPLICATION_H
#ifndef OGREAPPLICATION_H
#define OGREAPPLICATION_H
#include <QObject>
#include <Ogre.h>
class CNahGui;
class OgreWidget;
class OgreApplication : public QObject
{
Q_OBJECT
public:
OgreApplication(QObject *parent = 0);
~OgreApplication();
void setupNLoadResources();
void createScene();
public slots:
void initialise();
OgreWidget * createOgreWidget();
private:
Ogre::Root *ogreRoot;
Ogre::SceneManager *ogreSceneManager;
static int nbRenderWindows;
};
#endif // OGREAPPLICATION_H
To copy to clipboard, switch view to plain text mode
OgreApplication.cpp :
#include "OgreApplication.h"
#include "OgreWidget.h"
int OgreApplication::nbRenderWindows = 0;
OgreApplication
::OgreApplication(QObject *parent
) ogreRoot(0),
ogreSceneManager(0)
{
}
OgreApplication::~OgreApplication()
{
if(ogreRoot)
{
if(ogreSceneManager)
{
ogreRoot->destroySceneManager(ogreSceneManager);
}
}
delete ogreRoot;
}
void OgreApplication::initialise()
{
if (ogreRoot == 0)
{
ogreRoot = new Ogre::Root();
}
// initialised ?
if (!ogreRoot->isInitialised())
{
Ogre::RenderSystem *renderSystem = ogreRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
ogreRoot->setRenderSystem(renderSystem);
ogreRoot->initialise(false);
// Verify initialisation after initialise root
if (!ogreRoot->isInitialised())
{
return;
}
}
else
{
return;
}
ogreSceneManager = ogreRoot->createSceneManager(Ogre::ST_GENERIC);
QMessageBox::information(0,
"INFO",
"OgreApplication initialised.");
}
OgreWidget * OgreApplication::createOgreWidget()
{
nbRenderWindows++;
OgreWidget * og = new OgreWidget();
og->initialise(nbRenderWindows, ogreRoot, ogreSceneManager);
if (nbRenderWindows == 1)
{
setupNLoadResources();
createScene();
}
QMessageBox::information(0,
"INFO",
"OgreWidget initialised.");
return og;
}
void OgreApplication::setupNLoadResources()
{
// Load resource paths from config file
Ogre::ConfigFile cf;
cf.load("resources.cfg");
// Go through all sections & settings in the file
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;
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
// OS X does not set the working directory relative to the app,
// In order to make things portable on OS X we need to provide
// the loading with it's own bundle path location
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
Ogre::String(macBundlePath() + "/" + archName), typeName, secName);
#else
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
#endif
}
}
// Initialise, parse scripts etc
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
QMessageBox::information(0,
"INFO",
"Ressources initialised.");
}
void OgreApplication::createScene()
{
ogreSceneManager->setAmbientLight(Ogre::ColourValue(1,1,1));
Ogre::Entity *robotEntity = ogreSceneManager->createEntity("Robot", "robot.mesh");
Ogre::SceneNode *robotNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode("RobotNode");
robotNode->attachObject(robotEntity);
robotNode->yaw(Ogre::Radian(Ogre::Degree(-90)));
}
#include "OgreApplication.h"
#include "OgreWidget.h"
int OgreApplication::nbRenderWindows = 0;
OgreApplication::OgreApplication(QObject *parent)
: QObject(parent),
ogreRoot(0),
ogreSceneManager(0)
{
}
OgreApplication::~OgreApplication()
{
if(ogreRoot)
{
if(ogreSceneManager)
{
ogreRoot->destroySceneManager(ogreSceneManager);
}
}
delete ogreRoot;
}
void OgreApplication::initialise()
{
if (ogreRoot == 0)
{
ogreRoot = new Ogre::Root();
}
// initialised ?
if (!ogreRoot->isInitialised())
{
Ogre::RenderSystem *renderSystem = ogreRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
ogreRoot->setRenderSystem(renderSystem);
ogreRoot->initialise(false);
// Verify initialisation after initialise root
if (!ogreRoot->isInitialised())
{
return;
}
}
else
{
return;
}
ogreSceneManager = ogreRoot->createSceneManager(Ogre::ST_GENERIC);
QMessageBox::information(0, "INFO", "OgreApplication initialised.");
}
OgreWidget * OgreApplication::createOgreWidget()
{
nbRenderWindows++;
OgreWidget * og = new OgreWidget();
og->initialise(nbRenderWindows, ogreRoot, ogreSceneManager);
if (nbRenderWindows == 1)
{
setupNLoadResources();
createScene();
}
QMessageBox::information(0, "INFO", "OgreWidget initialised.");
return og;
}
void OgreApplication::setupNLoadResources()
{
// Load resource paths from config file
Ogre::ConfigFile cf;
cf.load("resources.cfg");
// Go through all sections & settings in the file
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;
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
// OS X does not set the working directory relative to the app,
// In order to make things portable on OS X we need to provide
// the loading with it's own bundle path location
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
Ogre::String(macBundlePath() + "/" + archName), typeName, secName);
#else
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
#endif
}
}
// Initialise, parse scripts etc
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
QMessageBox::information(0, "INFO", "Ressources initialised.");
}
void OgreApplication::createScene()
{
ogreSceneManager->setAmbientLight(Ogre::ColourValue(1,1,1));
Ogre::Entity *robotEntity = ogreSceneManager->createEntity("Robot", "robot.mesh");
Ogre::SceneNode *robotNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode("RobotNode");
robotNode->attachObject(robotEntity);
robotNode->yaw(Ogre::Radian(Ogre::Degree(-90)));
QMessageBox::information(0, "INFO", "Scene created.");
}
To copy to clipboard, switch view to plain text mode
Bookmarks