How to integrate Ogre3D into a Qt5 QML scene

Recently I’ve been checking out again how to integrate Ogre3D into a Qt application. My previous effort Cutexture can be found here, here and the code here. This was nice as a simple integration but didn’t use modern graphics systems as efficiently as it could.

Fortunately the people at Nokia (when they were still interested in Qt) did publish a demo application qmlogre here that integrates Ogre3D into a Qt Quick QML scene by having Ogre render into an OpenGL Frame Buffer Object (FBO) which is in turn added to the QML scene as a textured item. However, this demo was relying on internal Qt headers that are not supposed to be used in production projects.

With a helpful comment I found here, I was able to update the qmlogre example to no longer rely on those internal Qt headers and to build fine with the latest stable Qt 5.0.1. In the hope that others may find it useful, I’ve made the revised code available on my Github account at https://github.com/advancingu/QmlOgre

Let me know in the comments what you think.

Edit: Here is a video of the original qmlogre application.

Advertisements

19 thoughts on “How to integrate Ogre3D into a Qt5 QML scene

  1. Hi, first of all excellent work!
    How did you managed to compile Ogre for MinGW and get it work in Qt Creator (on Windows, if you compiled it on that platform)?

    Thanks for the reply in any case
    Cheers

  2. Thanks Edoardo.

    I haven’t tried to compile the project under Windows with MinGW as my development platform is Linux (Ubuntu). However, even under Ubuntu I had to tweak the .pro settings so that Ogre libraries are correctly discovered. Is there anything specific that doesn’t work for you?

  3. Hi Markus,

    Superb work. Was looking for this for quite some time. You nailed it. Kudos !!!

    Looking for more such interesting works. Good luck.

    C B K

  4. I’m looking through the provided code and noticed a couple of things.

    You’re creating an ogre manual texture each time you update the node. It would probably be a bit more efficient to create it once at initialization instead of creating and destroying it every 16ms.

    You on demand instantiate the ogre root and associated objects in the ogrenode object. It seems like those things should be created and owned by the ogreitem object.

    If I recall correctly ogre root is a singleton. Have you tried multiple instances of an ogreitem yet?

    Thanks again for putting this out in the wild for us to use.

  5. Hi Jay, good points and thanks for the feedback.

    The texture should only be recreated when “m_dirtyFBO“ is true, e.g. after changing the texture size. Otherwise it should reuse the original texture from initialization.

    OgreNode is not a great place to keep Ogre, you’re right. This is simply code I kept from the original example written by Nokia. I just started a new branch about an hour ago where I am refactoring the code to be a stand-alone library and this stuff will get untangled there. The first commit is on Github already (‘library’).

    Having multiple OgreItem instances is not supported in master at the moment. This should be possible however once the code has been refactored.

  6. Hi Markus,

    What we have to do in order to add a frame listener in your lib?
    Because if I try to set
    m_ogreEngine = new OgreEngine(this);
    m_root = m_ogreEngine->startEngine();
    m_ogreEngine->setupResources();

    m_ogreEngine->activateOgreContext();
    //pRenderWindow=m_ogreEngine->getRenderWindow();

    createScene();
    createFrameListener();

    // renderingLoop
    m_root->startRendering();

    while(true)
    {
    Ogre::WindowEventUtilities::messagePump();

    if(pRenderWindow->isClosed())
    std::cout<<"pRenderWindow close"<renderOneFrame())
    std::cout<<"root renderOneFrame"<doneOgreContext();
    emit(ogreInitialized());

    and use the frame listener i ‘ve defined, my Ogre window freezes…

    Do I realy need to use and defined a frame listener or can i use ogreitem to repaint my scene with new element?

    thanks!

  7. Hi,

    If you call Ogre’s messagePump in QmlOgre, you will be hijacking Qt’s event processing methods and that is why you are seeing your window freeze. With QmlOgre all window and I/O events are controlled by Qt.

    If you want to be notified every time a frame is rendered, you can emit a signal from https://github.com/advancingu/QmlOgre/blob/master/lib/ogreitem.cpp#L25 . See also http://qt-project.org/doc/qt-5.1/qtquick/qquickitem.html#updatePaintNode

    Markus

  8. Hi. I am trying to compile the library on MSVC2010. It compile and generate a DLL file qmlogre.dll. But it is not generating the “libqmlogre.lib” and I am not able to compile the example program. Could you give some help?

  9. I figured it out. I just add __declspec( dllexport ) to force the VS2010 generate the file.
    I am not a expert in QT and C++. So, I am not sure why the .pro conversion to VS2010 project doesn’t work fine. Anyway, I just inserted the small section of code below on beginning of each class and then I put OGREQML_API before each class definition on .H files. And I add OGREQML_EXPORTS on PreProcessor definitions (Project -> Configurations -> C/C++ -> PreProcessor definitions) .

    // ————- to force the libogreqml.lib generation
    #ifdef OGREQML_EXPORTS // source code will define this macro before including this header
    #define OGREQML_API __declspec( dllexport )
    #else
    #define OGREQML_API __declspec( dllimport )
    #endif

    Now it is compiling on VS2010 and running like a charm!

  10. Hi. I am using the OgreQML library. It is working very well. But I am having a problem that I can’t solve. I am trying to use the Particle System on Ogre3D. The program compile and I don’t get any error on runtime. But the particles can’t be seen. Did you notice some problem with particle emission?

  11. Hi Rodrigo,
    I’m not familiar with the way the particle system works in Ogre but I would assume the reason you’re not seeing particles is not related to QmlOgre but to plain Ogre programming. I would suggest to start investigating by running the same particle code but with plain Ogre, to see if it works there.

  12. Hi,
    I build everything but when I start the example, the render winow is black. I fix all the not found resources, check the ogre log. It is visible also the render window detached from the qml window even if in the code the methosd setVisible is false.
    any suggestion?

  13. Hi Dannox,
    Sorry for the late reply. Are you using Ogre 1.8? I believe 1.9 is not compatible with QmlOgre.

  14. Pingback: website

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s