Integrating Ogre into Qt ...

Problems building or running the engine, queries about how to use features etc.
tmason
Kobold
Posts: 39
Joined: Wed Feb 11, 2015 8:30 am
x 1

Integrating Ogre into Qt ...

Post by tmason »

Hello,

I am attempting to get the base Ogre3D engine running and I would like to get Ogre integrated into Qt.

I know that both Ogre3D and Qt has changed significantly since the last iteration of Qt/Ogre documentation (linked here) so I am trying to start from scratch.

The reason why I garner that the above link to the Qt/Ogre integration documentation is limited or outdated is that Qt highly recommends that you use a QWindow instead of QWidget for OpenGL drawing for performance reasons.

I am basing my current attempt at integration from the GLFW code posted here as it is the simplest I have seen so far.

What I am wondering so far is this:
  • Do you initialize Ogre3D before or after you initialize a rendering context and set up OpenGL functions for Qt?
  • I assume that overall once the rendering context and Ogre3D is initialized that Ogre3D is more or less a self-contained system meaning that other than input device feedback (mouse movements, screen size change, etc.) Ogre3D just needs the rendering context. Am I correct?
Thank you for your time.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Integrating Ogre into Qt ...

Post by jacmoe »

I wouldn't worry about it. :)

The 'problem' is that Qt has implemented a special QSurface subclass especially for OpenGL to be used with a special QPainter OpenGL context thingie.

However, since you are using Ogre, just set the paint engine to null in your QWidget class and just let Ogre render.
All Ogre needs is the window id (handle), and it will happily render both OpenGL and Direct3D on it.
We do that in Ogitor and it works a treat.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
tmason
Kobold
Posts: 39
Joined: Wed Feb 11, 2015 8:30 am
x 1

Re: Integrating Ogre into Qt ...

Post by tmason »

Hmmm, Window ID. Perhaps I am an idiot but how would I supply the Window ID/handle to Ogre3D?

Also, would that be a cross-platform implementation?
jacmoe wrote:I wouldn't worry about it. :)

The 'problem' is that Qt has implemented a special QSurface subclass especially for OpenGL to be used with a special QPainter OpenGL context thingie.

However, since you are using Ogre, just set the paint engine to null in your QWidget class and just let Ogre render.
All Ogre needs is the window id (handle), and it will happily render both OpenGL and Direct3D on it.
We do that in Ogitor and it works a treat.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Integrating Ogre into Qt ...

Post by jacmoe »

https://bitbucket.org/ogitor/ogitor/src ... at=default

Code: Select all

#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
    params["externalWindowHandle"] = Ogre::StringConverter::toString((size_t) (this->winId()));
#else
#if QT_VERSION < 0x050000
    const QX11Info info = this->x11Info();
    Ogre::String winHandle;
    winHandle  = Ogre::StringConverter::toString((unsigned long)(info.display()));
    winHandle += ":";
    winHandle += Ogre::StringConverter::toString((unsigned int)(info.screen()));
    winHandle += ":";
    winHandle += Ogre::StringConverter::toString((unsigned long)(this->winId()));
    winHandle += ":";
    winHandle += Ogre::StringConverter::toString((unsigned long)(info.visual()));

    params["externalWindowHandle"] = winHandle;

#elif QT_VERSION >= 0x050100 && defined(Q_WS_X11)
    const QX11Info info = this->x11Info();
    Ogre::String winHandle;
    winHandle  = Ogre::StringConverter::toString((unsigned long)(info.display()));
    winHandle += ":";
    winHandle += Ogre::StringConverter::toString((unsigned int)(info.appScreen()));
    winHandle += ":";
    winHandle += Ogre::StringConverter::toString((unsigned long)(this->winId()));

    params["externalWindowHandle"] = winHandle;
#else // only for the time between Qt 5.0 and Qt 5.1 when QX11Info was not included
    params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)(this->winId()));
#endif
#endif

#if defined(Q_OS_MAC)
    params["macAPI"] = "cocoa";   
    params["macAPICocoaUseNSView"] = "true";
#endif

    mRenderWindow = mOgreRoot->createRenderWindow( "QtOgitorRenderWindow",
        this->width(),
        this->height(),
        false,
        &params );

    mRenderWindow->resize(width(), height());
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Integrating Ogre into Qt ...

Post by jacmoe »

Also, take heed of this:

Code: Select all

QPaintEngine* OgreWidget::paintEngine() const
{
    // We don't want another paint engine to get in the way for our Ogre based paint engine.
    // So we return nothing.
    return NULL;
}
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
tmason
Kobold
Posts: 39
Joined: Wed Feb 11, 2015 8:30 am
x 1

Re: Integrating Ogre into Qt ...

Post by tmason »

Thank you; apologies if this was a simple thing.

I will try this out and update the thread appropriately.
dermont
Bugbear
Posts: 812
Joined: Thu Dec 09, 2004 2:51 am
x 42

Re: Integrating Ogre into Qt ...

Post by dermont »

And for Linux, unless you are running < Ogre1.6 you can replace:

Code: Select all

#else
#if QT_VERSION < 0x050000
    const QX11Info info = this->x11Info();
    Ogre::String winHandle;
    winHandle  = Ogre::StringConverter::toString((unsigned long)(info.display()));
    winHandle += ":";
    winHandle += Ogre::StringConverter::toString((unsigned int)(info.screen()));
    winHandle += ":";
    winHandle += Ogre::StringConverter::toString((unsigned long)(this->winId()));
    winHandle += ":";
    winHandle += Ogre::StringConverter::toString((unsigned long)(info.visual()));

    params["externalWindowHandle"] = winHandle;

#elif QT_VERSION >= 0x050100 && defined(Q_WS_X11)
    const QX11Info info = this->x11Info();
    Ogre::String winHandle;
    winHandle  = Ogre::StringConverter::toString((unsigned long)(info.display()));
    winHandle += ":";
    winHandle += Ogre::StringConverter::toString((unsigned int)(info.appScreen()));
    winHandle += ":";
    winHandle += Ogre::StringConverter::toString((unsigned long)(this->winId()));

    params["externalWindowHandle"] = winHandle;
#else // only for the time between Qt 5.0 and Qt 5.1 when QX11Info was not included
    params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)(this->winId()));
#endif

with:

Code: Select all

#else
    params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)(this->winId()));
tmason
Kobold
Posts: 39
Joined: Wed Feb 11, 2015 8:30 am
x 1

Re: Integrating Ogre into Qt ...

Post by tmason »

So, forgive me if I missed something simple:

On all of the examples I have seen a QWidget or QWindow needs a surface regardless of what you put on it. So, in all of the examples I have seen with Qt you need either a "raster" surface using QPainter or an "OpenGL" surface that Qt itself manages.

So, from what you have written above it seems like Ogre paints directly to the Window ID supplied. My problem then comes out to be this:
  • Do I still need to initialize a Raster surface or do I create a QWindow/QWidget that has no "surface" whatsoever?
  • Do I need to inform Ogre continuously about the window? For example, Qt has functions which basically translate to constantly informing the Qt-related functions to keep rendering despite nothing happening (setAnimating=true or something like that). I assume I still need to do this with the Ogre3D window. Is that true?
Thank you and again, I apologize if this was covered. I may have missed something from your posts.
User avatar
stealth977
Gnoll
Posts: 638
Joined: Mon Dec 15, 2008 6:14 pm
Location: Istanbul, Turkey
x 42

Re: Integrating Ogre into Qt ...

Post by stealth977 »

yes you will need to keep a timer with interval(1) and call TheWidgetContainingOGRE->update() and in that widgets paint event call OGRE::Root->renderOneFrame()
Ismail TARIM
Ogitor - Ogre Scene Editor
WWW:http://www.ogitor.org
Repository: https://bitbucket.org/ogitor
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Integrating Ogre into Qt ...

Post by jacmoe »

Strictly speaking, you don't need that timer event unless you are animating something in your Ogre scene, like textures, skeletons, etc.

Here is a most minimal impl :

Code: Select all

#ifndef OGREWIDGET_H
#define OGREWIDGET_H

#include <QWidget>
#include "EngineCore/EngineInterface.h"

class OgreWidget : public QWidget
{
    Q_OBJECT

public:
    OgreWidget(ScapeEngine::EngineInterface* engineInterface, QWidget *parent);
    ~OgreWidget();

    // Override QWidget::paintEngine to return NULL
    QPaintEngine* paintEngine() const; // Turn off QTs paint engine for the Ogre widget.

protected: // interface
    /** @name Inherited from QWidget
     */
    //@{
    virtual void paintEvent(QPaintEvent *pEvent);
    virtual void resizeEvent(QResizeEvent *rEvent);
    virtual void update();
    virtual void mousePressEvent(QMouseEvent *event);
    virtual void mouseMoveEvent(QMouseEvent *event);
    virtual void focusOutEvent(QFocusEvent *evt);
    virtual void focusInEvent(QFocusEvent *evt);
    //@}
private:
    ScapeEngine::EngineInterface* mEngineInterface;
    bool mHasView;
    bool mHasFocus;
};

#endif // OGREWIDGET_H

Code: Select all

#include "ogrewidget.h"
#include <sstream>
#include <QtGui/QFocusEvent>

OgreWidget::OgreWidget(ScapeEngine::EngineInterface *engineInterface, QWidget *parent)
    : mEngineInterface(engineInterface),
      mHasView(false),
      mHasFocus(false)
{
    if (!parent) {
        throw std::runtime_error("Parent widget supplied was uninitialised!"); // interface requirement
    }

    setFocusPolicy(Qt::WheelFocus);
    setMouseTracking(true);
    setAttribute(Qt::WA_NoBackground);
    setAttribute(Qt::WA_PaintOnScreen);

}

OgreWidget::~OgreWidget()
{

}

void OgreWidget::paintEvent(QPaintEvent *pEvent) {
    this->update();
}

QPaintEngine* OgreWidget::paintEngine() const
{
    // We don't want another paint engine to get in the way for our Ogre based paint engine.
    // So we return nothing.
    return NULL;
}


void OgreWidget::resizeEvent(QResizeEvent *rEvent)
{
    if (rEvent)
    {
        QWidget::resizeEvent(rEvent);
        this->update();
    }
}


void OgreWidget::mousePressEvent(QMouseEvent *event)
{
}

void OgreWidget::mouseMoveEvent(QMouseEvent *event)
{
}

void OgreWidget::focusOutEvent(QFocusEvent *evt)
{
    if (mHasView)
    {
        mEngineInterface->onRenderViewKillFocus(1);
    }
    mHasFocus = false;
    evt->setAccepted(true);
}

void OgreWidget::focusInEvent(QFocusEvent *evt)
{
    if (mHasView)
    {
        mEngineInterface->onRenderViewSetFocus(1);
    }
    mHasFocus = true;
    evt->setAccepted(true);
}


void OgreWidget::update()
{
    QWidget::update();
    if (!mHasView)
    {
        std::stringstream s;
        s << this->winId();
        mEngineInterface->createRenderView(1, s.str().c_str(), this->x(), this->y(), this->width(), this->height());
        mHasView = true;
    }
    else
    {
        mEngineInterface->onRenderViewSetFocus(1);
        mEngineInterface->onRenderViewMovedOrResized(1, this->x(), this->y(), this->width(), this->height());
        mEngineInterface->update();
    }
}
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
tmason
Kobold
Posts: 39
Joined: Wed Feb 11, 2015 8:30 am
x 1

Re: Integrating Ogre into Qt ...

Post by tmason »

Hello,

Thanks to everyone's help, I managed to get a bare-bones Ogre3D window working with just a QWindow versus a QWidget.

The difference is that a QWindow uses less resources than a QWidget in memory; perfect for getting Qt/Ogre3D instance with the smallest memory footprint.

Would love if anyone can offer comments or improvements.

Anyway, here goes:

plugins.cfg:

Code: Select all

# Defines plugins to load

# Define plugin folder
PluginFolder=Plugins

# Define plugins
#
#Commented out Direct3D for preference to use OpenGL but you can decide on your own.
#
# Plugin=RenderSystem_Direct3D9
# Plugin=RenderSystem_Direct3D11
Plugin=RenderSystem_GL
# Plugin=RenderSystem_GL3Plus
# Plugin=RenderSystem_GLES
# Plugin=RenderSystem_GLES2
Plugin=Plugin_ParticleFX
Plugin=Plugin_BSPSceneManager
Plugin=Plugin_CgProgramManager
Plugin=Plugin_PCZSceneManager
Plugin=Plugin_OctreeZone
Plugin=Plugin_OctreeSceneManager
QTOgreWindow.h (Header)

Code: Select all

#ifndef QTOGREWINDOW_H_
#define QTOGREWINDOW_H_

#ifndef QT_INCLUDES_
#define QT_INCLUDES_

#include <QtCore/QCoreApplication>
#include <QtCore/QString>
#include <QtCore/QVector>
#include <QtCore/QtAlgorithms>
#include <QtCore/QFlags>
#include <QtCore/qlist.h>
#include <QtCore/qurl.h>
#include <QtCore/qtimer.h>
#include <QtCore/qfile.h>
#include <QtCore/qdir.h>
#include <QtCore/qfileinfo.h>
#include <QtCore/qmath.h>
#include <QtCore/QByteArray>
#include <QtCore/QtDebug>
#include <QtCore/QtGlobal>
#include <QtCore/QDateTime>
#include <QtCore/QCryptographicHash>
#include <QtCore/qsysinfo.h>
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qstandardpaths.h>
#include <QtCore/qprocess.h>
#include <QtCore/qmimedata.h>

#include <QtGui/QGuiApplication>
#include <QtGui/QMatrix3x3>
#include <QtGui/QMatrix4x4>
#include <QtGui/QVector2D>
#include <QtGui/QVector3D>
#include <QtGui/QVector4D>
#include <QtGui/QOpenGLShaderProgram>
#include <QtGui/QScreen>
#include <QtGui/QWindow>
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QOpenGLFunctions_3_1>
#include <QtGui/QOpenGLContext>
#include <QtGui/QOpenGLPaintDevice>
#include <QtGui/QPainter>
#include <QtGui/qdesktopservices.h>
#include <QtGui/qclipboard.h>

#include <QtWidgets/qopenglwidget.h>
#include <QtWidgets/qapplication.h>
#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qgroupbox.h>
#include <QtWidgets/qmessagebox.h>
#include <QtWidgets/qdesktopwidget.h>
#include <QtWidgets/qdockwidget.h>
#include <QtWidgets/qmainwindow.h>
#include <QtWidgets/qfiledialog.h>
#include <QtWidgets/qstatusbar.h>
#include <QtWidgets/qtablewidget.h>
#include <QtWidgets/qdialogbuttonbox.h>
#include <QtWidgets/QAction>
#include <QtWidgets/QMenu>
#include <QtWidgets/qlabel.h>
#include <QtWidgets/qlineedit.h>
#include <QtWidgets/qtextedit.h>
#include <QtWidgets/qcheckbox.h>
#include <QtWidgets/qcombobox.h>
#include <QtWidgets/qpushbutton.h>
#include <QtWidgets/qscrollarea.h>
#include <QtWidgets/QMenubar>
#include <QtWidgets/QProgressBar>
#include <QtWidgets/qslider.h>
#include <QtWidgets/QToolBar>

#include <QtGui/QKeyEvent>

#include <QtNetwork/qnetworkaccessmanager.h>
#include <QtNetwork/qnetworkcookiejar.h>
#include <QtNetwork/qnetworkinterface.h>
#include <QtNetwork/qnetworkrequest.h>
#include <QtNetwork/qnetworkreply.h>
#include <QtNetwork/qsslerror.h>

#endif

#ifndef OGRE_INCLUDES_
#define OGRE_INCLUDES_

#include "OGRE/Ogre.h"

#endif

class QTOgreWindow : public QWindow {

	Q_OBJECT

public:

	explicit QTOgreWindow(QWindow *parent = NULL);
	~QTOgreWindow();

	virtual void render(QPainter *painter);
	virtual void render();

	virtual void initialize();

	void setAnimating(bool animating);

public slots:

	virtual void renderLater();
	virtual void renderNow();

	virtual bool eventFilter(QObject *target, QEvent *event);

protected:

	Ogre::Root* ogreRoot;
	Ogre::RenderWindow* ogreWindow;
	Ogre::SceneManager* ogreSceneMgr;
	Ogre::Camera* ogreCamera;
	Ogre::Viewport* ogreViewPort;

	bool m_update_pending;
	bool m_animating;

	virtual void keyPressEvent(QKeyEvent * ev);
	virtual void keyReleaseEvent(QKeyEvent * ev);
	virtual void exposeEvent(QExposeEvent *event);
	virtual bool event(QEvent *event);

private:

private slots:

};

#endif
QtOgreWindow.cpp (Implementation)

Code: Select all

#include "QTOgreWindow.h"


QTOgreWindow::QTOgreWindow(QWindow *parent) : QWindow(parent)
	, m_update_pending(false)
	, m_animating(false)
{

	setAnimating(true);
	installEventFilter(this);

}

QTOgreWindow::~QTOgreWindow()
{
	delete ogreRoot;
}

void QTOgreWindow::render(QPainter *painter)
{
	Q_UNUSED(painter);
}

void QTOgreWindow::initialize()
{

	ogreRoot = new Ogre::Root(Ogre::String("plugins.cfg"));
	Ogre::ConfigFile ogreConfig;

	/*

	ogreConfig.load("resources/resource_configs/resources.cfg");

	Ogre::ConfigFile::SectionIterator seci = ogreConfig.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);
		}
	}

	*/

	ogreRoot->setRenderSystem(ogreRoot->getAvailableRenderers()[0]);
	ogreRoot->initialise(false);

	Ogre::NameValuePairList parameters;

	parameters["currentGLContext"] = Ogre::String("false");

#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
	parameters["externalWindowHandle"] = Ogre::StringConverter::toString((size_t) (this->winId()));
#else
	parameters["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)(this->winId()));
#endif

#if defined(Q_OS_MAC)
	parameters["macAPI"] = "cocoa";
	parameters["macAPICocoaUseNSView"] = "true";
#endif

	ogreWindow = ogreRoot->createRenderWindow("QT Window", this->width(), this->height(), false, &parameters);
	ogreWindow->setVisible(true);

	ogreSceneMgr = ogreRoot->createSceneManager(Ogre::ST_GENERIC);
	ogreCamera = ogreSceneMgr->createCamera("MainCamera");

	ogreCamera->setPosition(Ogre::Vector3(0.0f, 0.0f, 10.0f));
	ogreCamera->lookAt(Ogre::Vector3(0.0f, 0.0f, -300.0f));
	ogreCamera->setNearClipDistance(5.0f);

	ogreViewPort = ogreWindow->addViewport(ogreCamera);
	ogreViewPort->setBackgroundColour(Ogre::ColourValue(0.4f, 0.3f, 0.1f));

	ogreCamera->setAspectRatio(Ogre::Real(ogreViewPort->getActualWidth()) / Ogre::Real(ogreViewPort->getActualHeight()));

	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);

	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

	ogreSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));

	Ogre::Light* light = ogreSceneMgr->createLight("MainLight");
	light->setPosition(20.0f, 80.0f, 50.0f);

}

void QTOgreWindow::render()
{
	
	Ogre::WindowEventUtilities::messagePump();
	ogreRoot->renderOneFrame();

}

void QTOgreWindow::renderLater()
{
	if (!m_update_pending) {
		m_update_pending = true;
		QApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
	}
}

bool QTOgreWindow::event(QEvent *event)
{
	switch (event->type()) {
	case QEvent::UpdateRequest:
		m_update_pending = false;
		renderNow();
		return true;
	default:
		return QWindow::event(event);
	}
}

void QTOgreWindow::exposeEvent(QExposeEvent *event)
{
	Q_UNUSED(event);

	if (isExposed())
		renderNow();
}

void QTOgreWindow::renderNow()
{
	if (!isExposed())
		return;

	bool needsInitialize = false;

	if (!ogreRoot) {
		needsInitialize = true;
	}

	if (needsInitialize) {
		initialize();
	}

	render();

	if (m_animating)
		renderLater();
}

bool QTOgreWindow::eventFilter(QObject *target, QEvent *event) {

	if (target == this) {

		if (event->type() == QEvent::Resize) {

			if (isExposed()) {

				ogreWindow->resize(this->width(), this->height());
				ogreCamera->setAspectRatio(Ogre::Real(ogreViewPort->getActualWidth()) / Ogre::Real(ogreViewPort->getActualHeight()));

			}
				

		}

	}

	return false;

}

void QTOgreWindow::keyPressEvent(QKeyEvent * ev) {



}

void QTOgreWindow::keyReleaseEvent(QKeyEvent * ev) {



}

void QTOgreWindow::setAnimating(bool animating)
{
	m_animating = animating;

	if (animating)
		renderLater();
}
tmason
Kobold
Posts: 39
Joined: Wed Feb 11, 2015 8:30 am
x 1

Re: Integrating Ogre into Qt ...

Post by tmason »

And, here is usage:

Code: Select all

#include "QTOgreWindow.h"
Using inside a QWidget:

Code: Select all

QTOgreWindow* ogreWindow = new QTOgreWindow();
QWidget* renderingContainer = QWidget::createWindowContainer(ogreWindow);
Or using the QWindow by itself for ultra-minimalist approach. Note that this uses the least amount of memory:

Code: Select all

QTOgreWindow* ogreWindow = new QTOgreWindow();
ogreWindow->showMaximized();
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 136

Re: Integrating Ogre into Qt ...

Post by spacegaier »

I think this should be added to the wiki, because the existing Qt <--> Ogre integration snippets are outdated: http://www.ogre3d.org/tikiwiki/tiki-ind ... I+Toolkits Would you be willing to create the new page?

One thing I saw is that your QTOgreWindow.h includes quite a lot of unnecessary includes.
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
User avatar
Herb
Orc
Posts: 412
Joined: Thu Jun 04, 2009 3:21 am
Location: Kalamazoo,MI
x 38

Re: Integrating Ogre into Qt ...

Post by Herb »

So, is the only difference is memory usage between QWindow and QWidget? I'm currently doing a QWidget style for my app (not using the QT OpenGL, like Ogitor). Wondering if there was any other advantages to switch...

Agree with spacegaier, it'd be great to add another wiki page. I spent many hours tweaking my Ogre Widget to be similar to Ogitor as I didn't want Qt's OpenGL, and Qt5 just messed my world up when I tried porting it from 4.8.x to 5.4. Works now, but a wiki page would same some folks time.

Thanks for sharing!
tmason
Kobold
Posts: 39
Joined: Wed Feb 11, 2015 8:30 am
x 1

Re: Integrating Ogre into Qt ...

Post by tmason »

spacegaier wrote:I think this should be added to the wiki, because the existing Qt <--> Ogre integration snippets are outdated: http://www.ogre3d.org/tikiwiki/tiki-ind ... I+Toolkits Would you be willing to create the new page?

One thing I saw is that your QTOgreWindow.h includes quite a lot of unnecessary includes.
Sure, no problem on a new page. What sort of permissions do I need?

This was part of a larger project and thus all of the includes. I will reduce the number of includes to the bare-bones and repost.
tmason
Kobold
Posts: 39
Joined: Wed Feb 11, 2015 8:30 am
x 1

Re: Integrating Ogre into Qt ...

Post by tmason »

Herb wrote:So, is the only difference is memory usage between QWindow and QWidget? I'm currently doing a QWidget style for my app (not using the QT OpenGL, like Ogitor). Wondering if there was any other advantages to switch...

Agree with spacegaier, it'd be great to add another wiki page. I spent many hours tweaking my Ogre Widget to be similar to Ogitor as I didn't want Qt's OpenGL, and Qt5 just messed my world up when I tried porting it from 4.8.x to 5.4. Works now, but a wiki page would same some folks time.

Thanks for sharing!
Here are two links: StackOverflow and the documentation on QWindow itself.

Long story short; a QWindow represents the bare minimum window of the Qt window management system.

The problem with using a QWidget for Ogre3D or tons of OpenGL content is that QWidget adds a lot of stuff that you simply don't need for OpenGL (or Ogre3D) drawing. So it's not just the memory footprint but all of the stuff QWidget does behind the scenes all of the time which slows things down.

QWindow essentially gives you a cross platform surface on which to draw Ogre3D content on.

I encourage those wanting to use Qt + Ogre3D to try both approaches and see which is faster for themselves. I will bet money that the QWindow approach is much faster and easier...
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 136

Re: Integrating Ogre into Qt ...

Post by spacegaier »

tmason wrote:
spacegaier wrote:I think this should be added to the wiki, because the existing Qt <--> Ogre integration snippets are outdated: http://www.ogre3d.org/tikiwiki/tiki-ind ... I+Toolkits Would you be willing to create the new page?

One thing I saw is that your QTOgreWindow.h includes quite a lot of unnecessary includes.
Sure, no problem on a new page. What sort of permissions do I need?

This was part of a larger project and thus all of the includes. I will reduce the number of includes to the bare-bones and repost.
I created a stub page for you: http://www.ogre3d.org/tikiwiki/tiki-ind ... e+into+QT5

Just log into the wiki and start editing :) . No special permissions needed.
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
tmason
Kobold
Posts: 39
Joined: Wed Feb 11, 2015 8:30 am
x 1

Re: Integrating Ogre into Qt ...

Post by tmason »

spacegaier wrote: I created a stub page for you: http://www.ogre3d.org/tikiwiki/tiki-ind ... e+into+QT5

Just log into the wiki and start editing :) . No special permissions needed.
First version done. Open to comments and review.
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 136

Re: Integrating Ogre into Qt ...

Post by spacegaier »

Looking really good. Thank you very much!

PS: I split your page into three sections and added a table of contents for easy navigation.
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
Transporter
Minaton
Posts: 933
Joined: Mon Mar 05, 2012 11:37 am
Location: Germany
x 110

Re: Integrating Ogre into Qt ...

Post by Transporter »

I’ve modified the Qt window from the wiki (http://www.ogre3d.org/tikiwiki/tiki-ind ... e+into+QT5).

What’s new?
  • works with Ogre 1.x and 2.0 (2.1 not tested yet)
  • works with Qt 5.4.0 (5.4.1 not tested yet)
  • create scene is outsourced to a virtual function; instead of modifying the code you can override the function with your own code
  • OpenGL and DirectX are working on Windows
Feel free to improve my code.
QTOgreWindow.h
QTOgreWindow.cpp
tmason
Kobold
Posts: 39
Joined: Wed Feb 11, 2015 8:30 am
x 1

Re: Integrating Ogre into Qt ...

Post by tmason »

This is great!

I think what myself and other folks need to work on now is example integration of keyboard and mouse code.

I have a snippet inside the code for basic keyboard movement of the camera but integration with OIS and more mature input classes with Qt would probably go a long way.
przemir
Halfling
Posts: 68
Joined: Sun May 11, 2014 7:55 pm
Location: Poland
x 21

Re: Integrating Ogre into Qt ...

Post by przemir »

Transporter wrote:I’ve modified the Qt window from the wiki (http://www.ogre3d.org/tikiwiki/tiki-ind ... e+into+QT5).
I've modified from older sources, but this solution is much better.

In my project OgreWidget was derived from QWidget, FrameListener (I've frameRenderingQueued instead of renderOneFrame procedure). MainWindow contained this widget as well as QDockWidget. Hovewer I encountered troubles with Qt 5.4 (focus cannot be gained by clicking on OgreWidget), whereas Qt 4.8 worked just fine.
Transporter wrote:Feel free to improve my code.
I added parts of my solution to this project:
- MainWindow with DockWidget
tmason wrote:... example integration of keyboard and mouse code.
- SdkQtCameraMan (SdkCameraMan with QKeyEvent, QMouseEvent, QWheelEvent instead of OIS)

I also added QElapsedTimer to update this SdkQtCameraMan.
You do not have the required permissions to view the files attached to this post.
tmason
Kobold
Posts: 39
Joined: Wed Feb 11, 2015 8:30 am
x 1

Re: Integrating Ogre into Qt ...

Post by tmason »

First compile with the camera, very smooth movement!

Also, just so folks know, I am using Qt 5.4.1, the latest, with Ogre3D :D :D :D

You may try it yourselves.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 139

Re: Integrating Ogre into Qt ...

Post by c6burns »

Image

Couldn't resist :lol:
przemir
Halfling
Posts: 68
Joined: Sun May 11, 2014 7:55 pm
Location: Poland
x 21

Re: Integrating Ogre into Qt ...

Post by przemir »

QElapsedTimer was unnecessary. I've changed it to FrameListener.
You do not have the required permissions to view the files attached to this post.