Integrating Ogre into Qt ...

Problems building or running the engine, queries about how to use features etc.
Transporter
Minaton
Posts: 933
Joined: Mon Mar 05, 2012 11:37 am
Location: Germany
x 110

Re: Integrating Ogre into Qt ...

Post by Transporter »

przemir wrote:QElapsedTimer was unnecessary. I've changed it to FrameListener.
Great!

Now, there is a signal (entitySelected) for element picking.

Edit: I've updated the wiki page for the last changes.
Ludobaka
Gnoblar
Posts: 7
Joined: Wed Dec 17, 2014 4:20 pm

Re: Integrating Ogre into Qt ...

Post by Ludobaka »

I was looking for a better way for using Compositor because I had some troubles with FBO management with a QGLWidget. Thanks for the QTOgreWindow ;)

However, is it possible to get multiple QTOgreWindow in the same App ? I changed the way you get the ogre root to instanciate it once :

Code: Select all

    m_ogreRoot = ::Ogre::Singleton< ::Ogre::Root >::getSingletonPtr();
    if (m_ogreRoot == NULL)
    {
#ifdef _MSC_VER
        m_ogreRoot = new Ogre::Root(Ogre::String(<PATH_TO_THE_PLUGINS_CFG>));
#else
        m_ogreRoot = new Ogre::Root(Ogre::String(<PATH_TO_THE_PLUGINS_CFG>));
#endif
    }
Now, I've got this error at the ogreRoot->initialise(false) call :
OgreSingleton.h :80 : Ogre::Singleton<Ogre::TextureManager>::Singleton() [T = Ogre::TextureManager]: assert « !msSingleton » failed.
Someone got any clue? Is this related to current OpenGL context?
przemir
Halfling
Posts: 68
Joined: Sun May 11, 2014 7:55 pm
Location: Poland
x 21

Re: Integrating Ogre into Qt ...

Post by przemir »

Ludobaka wrote: However, is it possible to get multiple QTOgreWindow in the same App ?
Ludobaka wrote: Now, I've got this error at the ogreRoot->initialise(false) call
You tried to call this function twice (because of two QTOgreWindows)? Inside initialise function OgreRoot allocate singletons, and TextureManager is one of them. Assertion protect from second allocation attempt.

Edit: You may check code from: https://bitbucket.org/MindCalamity/qtogre/src (example with two OgreWidgets).
More info about that link in thread: http://www.ogre3d.org/forums/viewtopic.php?f=2&t=69432
Transporter
Minaton
Posts: 933
Joined: Mon Mar 05, 2012 11:37 am
Location: Germany
x 110

Re: Integrating Ogre into Qt ...

Post by Transporter »

Bugfix:
replace

Code: Select all

virtual void mouseWheelEvent(QWheelEvent* e);
by

Code: Select all

virtual void wheelEvent(QWheelEvent* e);
to override the correct event function.
Attachments
QTOgreWindow.h
(2.6 KiB) Downloaded 95 times
QTOgreWindow.cpp
(13.69 KiB) Downloaded 116 times
WuceBrain
Gnoblar
Posts: 5
Joined: Wed Aug 17, 2016 11:44 pm

Re: Integrating Ogre into Qt ...

Post by WuceBrain »

I used the provided example to integrate Ogre with Qt5 in my example. It works nicely.

My problem is the following:

I can create as many windows (ogre cameras, ogre render windows, etc) as I wish during the start up of my application. Once the simulator is running, the function Ogre::Root->renderOneFrame() hangs after I create new Qt Window (with it's own camera, render window, etc).

This is something that I am trying to solve for quite some time now, so I would be very thankful for any help.

Cheers, WB
sevketcaba
Gnoblar
Posts: 7
Joined: Fri Dec 16, 2016 5:34 pm

Re: Integrating Ogre into Qt ...

Post by sevketcaba »

Hello everyone, i have some code similar to this.

Code works well on 1.9 and 2.1 from bitbucket, but i have some issues with 1.10 from github. GL and GL3+ implementations just crashes, DX implementations do not embed the Ogre RenderWindow in QWindow. So there pops up 2 windows, one is a QMainWindow, which contains the QWindow with the QWidget::createWindowContainer method, and the other is the Ogre's render window.

If i press the mousebutton and move on QMainWindow, then focus on the Ogre window, it updates itself and appearently mouse events were propagated towards it. But, obviously update events are not propagated, since i have to unfocus and focus on Ogre window to make it update itself.

Anyone here integrated the 1.10 version from github into Qt and had same issues? Here is the relevant part of the code;

Code: Select all


   mRoot = new Ogre::Root(Ogre::String("config/plugins.cfg"),
                           Ogre::String("config/ogre.cfg"),
                           Ogre::String("log/ogre.log"));

    Ogre::LogManager::getSingleton().setLogDetail(Ogre::LL_BOREME);
    initializeResources();

    mRenderSystem = mRoot->getRenderSystemByName(mEngine.toStdString());
    /* i did not need this block in 1.9 and 2.1 */
    QString dimensions = QString("%1 x %2").arg(width()).arg(height());
    mRenderSystem->setConfigOption("Video Mode", dimensions.toStdString());
    mRenderSystem->setConfigOption("Full Screen", "No");
    mRenderSystem->setConfigOption("VSync", "Yes");
    /* end of block */
    mRoot->setRenderSystem(mRenderSystem);
    mRoot->initialise(false);

    Ogre::NameValuePairList tParameters;

    if (mRenderSystem->getName().find("GL") <= mRenderSystem->getName().size()) // i did not need this line in 1.9 and 2.1
        tParameters["currentGLContext"] = Ogre::String("false"); // this value was true in 1.9 and 2.1

    tParameters["externalWindowHandle"] = Ogre::StringConverter::toString((size_t) (winId()));
    tParameters["parentWindowHandle"] = Ogre::StringConverter::toString((size_t) (winId())); // i did not need this line in 1.9 and 2.1
    tParameters["vsync"] = Ogre::String("true");
    tParameters["FSAA"] = "8";
    mRenderWindow = mRoot->createRenderWindow(QString("QtWindow_%1").arg(mInstanceNumber).toStdString(), width(), height(), false, &tParameters);
    mRenderWindow->setVisible(true);

Edit: It seems update events are also sent, and
mRoot->renderOneFrame();
line is executed continuously, but somehow window content does not update
sevketcaba
Gnoblar
Posts: 7
Joined: Fri Dec 16, 2016 5:34 pm

Re: Integrating Ogre into Qt ...

Post by sevketcaba »

Okay guys, i found the issue, it seems Ogre::StringConverter::parseSizeT does not do what it has to do, it always returns ZERO. I double checked the class with the 2.1 branch from bitbucket, and they are extremely different. I am surprised that, a base helper class like this can change this much over time. I will try to use the 2.1 version in 1.10.3 and see if it's as easy as it sounds.
sevketcaba
Gnoblar
Posts: 7
Joined: Fri Dec 16, 2016 5:34 pm

Re: Integrating Ogre into Qt ...

Post by sevketcaba »

I did try it, but it seems, it will be a long journey, so i did this for now, and it works

Code: Select all

    size_t StringConverter::parseSizeT(const String& val, size_t defaultValue)
    {
       // size_t ret;
        //return sscanf(val.c_str(), "%zu", &ret) == 1 ? ret : defaultValue;
		StringStream str(val);
		//if (msUseLocale)
		//	str.imbue(msLocale);
		size_t ret = defaultValue;
		if (!(str >> ret))
			return defaultValue;

		return ret;
    }
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Integrating Ogre into Qt ...

Post by paroj »

does the sample browser work? which version of MSVC are you using? maybe %zu is not recognized.
sevketcaba
Gnoblar
Posts: 7
Joined: Fri Dec 16, 2016 5:34 pm

Re: Integrating Ogre into Qt ...

Post by sevketcaba »

I used MSVC12 (VS2013) x64, and you might be right, MSVC does not support it according to this link;

https://msdn.microsoft.com/en-us/librar ... .120).aspx

not z, but I (capital i, not L) must be used for msvc (also for 2015)


SampleBrowser question;
I did not check if it was running before, i just checked but it crashes within msvcr120.dll
gabbsson
Halfling
Posts: 65
Joined: Wed Aug 08, 2018 9:03 am
x 13

Re: Integrating Ogre into Qt ...

Post by gabbsson »

I used the wiki post http://wiki.ogre3d.org/Integrating+Ogre+into+QT5, which was based on this thread to create a working integration of Ogre 1.11 with Qt5. It rendered models, manual objects and so on.

I'm now trying to update to 2.1 and it has proven difficult. While I can compile and run the code the moment I try to add or create some type of mesh or manual object it crashes, claiming it can't find Hlms datablock. I have seen in other threads that it is required to register Hlms which I'm quite sure is not being done in my code (or the the wiki template). While I realize it is part of what needs to be added I haven't been able to understand how to go about it.

I have done my best to read and understand the tutorials provided for Ogre 2.1. The class GraphicsSystem is what registers Hlms but I'm not sure how to consolidate that with the QTOgreWindow.

My on topic question is:
Does anyone have a working example of QtOgreWindow for 2.1?

Ps. I am new to Ogre and C++ (not to mention posting on forums).
I usually just keep trying on my own til it works but figured it can't hurt to ask.
srd
Gnoblar
Posts: 21
Joined: Sun Jan 14, 2018 6:12 am

Re: Integrating Ogre into Qt ...

Post by srd »

I too am trying to integrate Qt in 2.1, and it has been very difficult. I've seen the wiki page w/ Qt5, but it's so far from how 2.1 works. I've been working from the tutorials and am using tutorial01 and now have an ogre window, but can't figure out how to put this in a QWindow. If you find a way, I hope you can let us know. Thanks.
dermont
Bugbear
Posts: 812
Joined: Thu Dec 09, 2004 2:51 am
x 42

Re: Integrating Ogre into Qt ...

Post by dermont »

gabbsson wrote: Wed Aug 08, 2018 9:36 am I used the wiki post http://wiki.ogre3d.org/Integrating+Ogre+into+QT5, which was based on this thread to create a working integration of Ogre 1.11 with Qt5. It rendered models, manual objects and so on.

I'm now trying to update to 2.1 and it has proven difficult. While I can compile and run the code the moment I try to add or create some type of mesh or manual object it crashes, claiming it can't find Hlms datablock. I have seen in other threads that it is required to register Hlms which I'm quite sure is not being done in my code (or the the wiki template). While I realize it is part of what needs to be added I haven't been able to understand how to go about it.

I have done my best to read and understand the tutorials provided for Ogre 2.1. The class GraphicsSystem is what registers Hlms but I'm not sure how to consolidate that with the QTOgreWindow.

My on topic question is:
Does anyone have a working example of QtOgreWindow for 2.1?

Ps. I am new to Ogre and C++ (not to mention posting on forums).
I usually just keep trying on my own til it works but figured it can't hurt to ask.
Try copying the registerResouces/registerHlms to your project, e.g:

Code: Select all


//headers
#include "OgreHlmsManager.h"
#include "Hlms/Unlit/OgreHlmsUnlit.h"
#include "Hlms/Unlit/OgreHlmsUnlitDatablock.h"

#include "OgreHlms.h"
#include "OgreHlmsDatablock.h"

#include "Hlms/Pbs/OgreHlmsPbs.h"
#include "Hlms/Pbs/OgreHlmsPbsDatablock.h"
#include "Hlms/Pbs/OgreHlmsPbs.h"
..

     virtual void registerResouces(void);
     virtual void registerHlms(void);


    //-----------------------------------------------------------------------------------
    void QTOgreWindow::registerResouces(void)
    {
        Ogre::Root* mRoot = Ogre::Root::getSingletonPtr();
        // 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();
            if( secName != "Hlms" )
            {

            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);
            }
            }
        }
    }

    //-----------------------------------------------------------------------------------
    void QTOgreWindow::registerHlms(void)
    {
        Ogre::Root* mRoot = Ogre::Root::getSingletonPtr();
        Ogre::ConfigFile cf;
        Ogre::String mResourcePath="";

        cf.load("./resources2.cfg" );

        Ogre::String dataFolder = cf.getSetting( "DoNotUseAsResource", "Hlms", "" );

        if( dataFolder.empty() )
            dataFolder = "./";
        else if( *(dataFolder.end() - 1) != '/' )
            dataFolder += "/";

        Ogre::RenderSystem *renderSystem = mRoot->getRenderSystem();

        Ogre::String shaderSyntax = "GLSL";
        if( renderSystem->getName() == "Direct3D11 Rendering Subsystem" )
            shaderSyntax = "HLSL";
        else if( renderSystem->getName() == "Metal Rendering Subsystem" )
            shaderSyntax = "Metal";

        Ogre::Archive *archiveLibrary = Ogre::ArchiveManager::getSingletonPtr()->load(
                        dataFolder + "Hlms/Common/" + shaderSyntax,
                        "FileSystem", true );
        Ogre::Archive *archiveLibraryAny = Ogre::ArchiveManager::getSingletonPtr()->load(
                        dataFolder + "Hlms/Common/Any",
                        "FileSystem", true );
        Ogre::Archive *archivePbsLibraryAny = Ogre::ArchiveManager::getSingletonPtr()->load(
                        dataFolder + "Hlms/Pbs/Any",
                        "FileSystem", true );

        Ogre::ArchiveVec library;
        library.push_back( archiveLibrary );
        library.push_back( archiveLibraryAny );

        Ogre::Archive *archiveUnlit = Ogre::ArchiveManager::getSingletonPtr()->load(
                        dataFolder + "Hlms/Unlit/" + shaderSyntax,
                        "FileSystem", true );

        Ogre::HlmsUnlit *hlmsUnlit = OGRE_NEW Ogre::HlmsUnlit( archiveUnlit, &library );
        Ogre::Root::getSingleton().getHlmsManager()->registerHlms( hlmsUnlit );

        Ogre::Archive *archivePbs = Ogre::ArchiveManager::getSingletonPtr()->load(
                        dataFolder + "Hlms/Pbs/" + shaderSyntax,
                        "FileSystem", true );
        library.push_back( archivePbsLibraryAny );
        Ogre::HlmsPbs *hlmsPbs = OGRE_NEW Ogre::HlmsPbs( archivePbs, &library );
        Ogre::Root::getSingleton().getHlmsManager()->registerHlms( hlmsPbs );
        library.pop_back();

        if( renderSystem->getName() == "Direct3D11 Rendering Subsystem" )
        {
            //Set lower limits 512kb instead of the default 4MB per Hlms in D3D 11.0
            //and below to avoid saturating AMD's discard limit (8MB) or
            //saturate the PCIE bus in some low end machines.
            bool supportsNoOverwriteOnTextureBuffers;
            renderSystem->getCustomAttribute( "MapNoOverwriteOnDynamicBufferSRV",
                                              &supportsNoOverwriteOnTextureBuffers );

            if( !supportsNoOverwriteOnTextureBuffers )
            {
                hlmsPbs->setTextureBufferDefaultSize( 512 * 1024 );
                hlmsUnlit->setTextureBufferDefaultSize( 512 * 1024 );
            }
        }
    }

And then after creating the render window:

Code: Select all

    ...
    m_ogreWindow->setVisible(true);
    registerResouces();
    registerHlms();
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(true);
    ...
srd
Gnoblar
Posts: 21
Joined: Sun Jan 14, 2018 6:12 am

Re: Integrating Ogre into Qt ...

Post by srd »

Any advice on what it takes to get GraphicsSystem into QMainWindow. I'm trying to learn the logic from the rendering approach in the 2.1 samples and would like to continue down this route. I have the rendering window appearing, but not sure what it takes to get this into a QMainWindow.
srd
Gnoblar
Posts: 21
Joined: Sun Jan 14, 2018 6:12 am

Re: Integrating Ogre into Qt ...

Post by srd »

Trying to get GraphicsSystem into the main window. I added QWindow as a class to inherit from, hoping to then upcast in the call to createWindowContainer. Hoping someone can help me get past this error which I thought should work.

Code: Select all

// --- graphicssystem.h
    class GraphicsSystem : public BaseSystem, public QWindow,
        public Ogre::UniformScalableTask
    {
    protected:
        Ogre::RenderWindow *mRenderWindow;

// --- mainwindow.h
class MainWindow : public QMainWindow
{
    private:
        QWidget* renderWidget;
        Ogre::RenderWindow* renderWindow;

// mainwindow.cpp
MainWindow::MainWindow())
{
    // ...
    renderWindow = graphicsSystem.getRenderWindow();

    // ...
    renderWidget = QWidget::createWindowContainer(
        static_cast<QWindow*>(renderWindow));

              
mainwindow.cpp: In constructor ‘MainWindow::MainWindow()’:                                                              
mainwindow.cpp:89:35: error: invalid static_cast from type ‘Ogre::RenderWindow*’ to type ‘QWindow*’                     
   static_cast<QWindow*>(renderWindow));
                                     ^
make[4]: *** [Makefile:668: mainwindow.o] Error 1
qfwfq
Gnoblar
Posts: 11
Joined: Mon Aug 25, 2014 4:47 pm
Contact:

Re: Integrating Ogre into Qt ...

Post by qfwfq »

I don't think this matches your use case, but I thought I would share how I am integrating Qt and Ogre 3D 2.1 in our game, in case it is useful to someone :) This is using the GL3Plus renderer in Ogre.

We are using Qt Quick, so I set up Ogre 3D to first adopt the current GL context used by Qt, and render the scene into an render texture. Then I hook this into Qt Quick using QQuickFramebufferObject. The only issue I had with this is that QOpenGLFramebufferObject does not support attaching to a render texture created elsewhere. So I hacked this in the Qt code so that if you request an FBO with size 0,0, then it will create an FBO for the currently bound texture. If anyone is interested, then I can share the code for the hack (it is not upstreaming quality but gets the job done for me).

Mostly this works perfectly, at least on Windows. There think was some context pollution affecting the distance field text in Qt, but I never bothered to fix that since we use the native text render type anyway.
gabbsson
Halfling
Posts: 65
Joined: Wed Aug 08, 2018 9:03 am
x 13

Re: Integrating Ogre into Qt ...

Post by gabbsson »

I managed to get it work a while ago using the solution similar to what dermont suggested in an above post.
Specifically I used a code snippet from this project: https://github.com/Ybalrid/Qt5Ogre21

Which made my project run. Since then I've hit multiple new problems which I plan to make a new post for unless I find answers somewhere.

So to summarize the solution:

Copy HLMS/Hlms folder from sample or the github project I mentioned earlier.
Add the path to the folder(s) as a resource location (example seen in the github project).
Register Hlms after creating a renderwindow in initialization.

That was all I needed to add to make it compile and run.
Post Reply