How to setup Ogre3D in Qt Creator with MinGW
-
Hello,
I built Ogre3D with CMake GUI and MingGW statically. I used MinGW from Qt from here:
C:\Qt5\Tools\mingw810_32\bin
.Now I have libraries (.a) for Ogre3D. I create an Empty Project with qmake. It works with SFML but I cannot run this simple example from Ogre3D repository: BasicTutorial1.cpp
I included all libraries from Ogre3D. But I have 598 errors. My setttings:
CONFIG += c++11 CONFIG -= console INCLUDEPATH += "E:\_Projects\Temp\ogre-13.1.1\dist\include" INCLUDEPATH += "E:\_Projects\Temp\ogre-13.1.1\OgreMain\include" INCLUDEPATH += "E:\_Projects\Temp\ogre-13.1.1\Components\Bites\include" INCLUDEPATH += "E:\_Projects\Temp\ogre-13.1.1\Components\RTShaderSystem\include" LIBS += -L"E:\_Projects\Temp\ogre-13.1.1\dist\lib" #LIBS += -lCodec_STBIStatic -lOgreBitesStatic -lOgreMainStatic -lOgreRTShaderSystemStatic -lPlugin_ParticleFXStatic LIBS += -lCodec_STBIStatic -lDefaultSamples -lOgreBitesStatic -lOgreGLSupportStatic -lOgreMainStatic -lOgreMeshLodGeneratorStatic -lOgreOverlayStatic -lOgrePagingStatic -lOgrePropertyStatic -lOgreRTShaderSystemStatic -lOgreTerrainStatic -lOgreVolumeStatic -lPlugin_BSPSceneManagerStatic -lPlugin_DotSceneStatic -lPlugin_OctreeSceneManagerStatic -lPlugin_OctreeZoneStatic -lPlugin_ParticleFXStatic -lPlugin_PCZSceneManagerStatic -lRenderSystem_GL3PlusStatic -lRenderSystem_GLES2Static -lRenderSystem_GLStatic LIBS += -L"E:\_Projects\Temp\ogre-13.1.1\dist\Dependencies\lib" LIBS += -lSDL2 -lfreetype -lpugixml LIBS += -lopengl32 SOURCES += \ main.cpp
Errors:
-
It was a problem with the libs order: Why does the order in which libraries are linked sometimes cause errors in GCC?
I found the right order:
CONFIG += c++11 CONFIG -= console INCLUDEPATH += "E:\_Projects\Temp\ogre-13.1.1\dist\include" INCLUDEPATH += "E:\_Projects\Temp\ogre-13.1.1\OgreMain\include" INCLUDEPATH += "E:\_Projects\Temp\ogre-13.1.1\Components\Bites\include" INCLUDEPATH += "E:\_Projects\Temp\ogre-13.1.1\Components\RTShaderSystem\include" LIBS += -L"E:\_Projects\Temp\ogre-13.1.1\dist\lib" #LIBS += -lCodec_STBIStatic -lOgreBitesStatic -lOgreMainStatic -lOgreRTShaderSystemStatic -lPlugin_ParticleFXStatic LIBS += -lDefaultSamples -lOgreBitesStatic -lRenderSystem_GL3PlusStatic -lOgreGLSupportStatic -lOgreMeshLodGeneratorStatic -lOgreOverlayStatic -lOgrePagingStatic -lOgrePropertyStatic -lOgreRTShaderSystemStatic -lOgreVolumeStatic -lPlugin_BSPSceneManagerStatic -lPlugin_DotSceneStatic -lPlugin_OctreeSceneManagerStatic -lPlugin_OctreeZoneStatic -lPlugin_ParticleFXStatic -lPlugin_PCZSceneManagerStatic -lRenderSystem_GLES2Static -lRenderSystem_GLStatic -lOgreMainStatic -lOgreTerrainStatic -lCodec_STBIStatic -lzlibstatic LIBS += -L"E:\_Projects\Temp\ogre-13.1.1\dist\Dependencies\lib" LIBS += -lSDL2main -lSDL2.dll -lfreetype -lpugixml LIBS += -lopengl32 -lgdi32 SOURCES += \ main.cpp
-
Hi,
Are you using a pre-built version of Ogre ?
Which compiler was used to build it ?
Is the build for the correct architecture ? -
I use Windows 10 64-bit. I have only one compiler on my laptop. It is MinGW 32-bit that is from Qt 5.15.2 32-bit:
>> mingw32-make -version GNU Make 4.2.1 Built for i686-w64-mingw32
I used this compiler with "CMake GUI" that is 32-bit:
to build Ogre 13.1.1 from source:
I clicked "Configure". I checked "Static Plugins" and "Ogre Static". I clicked "Configure" again. I clicked "Generate". After generating (it takes ~20 minutes) I typed this command for building:
mingw32-make
. After this I have these libraries:libCodec_STBIStatic.a libDefaultSamples.a libOgreBitesStatic.a libOgreGLSupportStatic.a libOgreMainStatic.a libOgreMeshLodGeneratorStatic.a libOgreOverlayStatic.a libOgrePagingStatic.a libOgrePropertyStatic.a libOgreRTShaderSystemStatic.a libOgreTerrainStatic.a libOgreVolumeStatic.a libPlugin_BSPSceneManagerStatic.a libPlugin_DotSceneStatic.a libPlugin_OctreeSceneManagerStatic.a libPlugin_OctreeZoneStatic.a libPlugin_ParticleFXStatic.a libPlugin_PCZSceneManagerStatic.a libRenderSystem_GL3PlusStatic.a libRenderSystem_GLES2Static.a libRenderSystem_GLStatic.a
And these:
-
I have Python 64-bit because I tried to use the
ogre-python
module. This module do not work with Python 32-bit. -
You should double check the architecture anyway.
I would also start with a shared build of Ogre as it often is easier to link to.
-
It was a problem with the libs order: Why does the order in which libraries are linked sometimes cause errors in GCC?
I found the right order:
CONFIG += c++11 CONFIG -= console INCLUDEPATH += "E:\_Projects\Temp\ogre-13.1.1\dist\include" INCLUDEPATH += "E:\_Projects\Temp\ogre-13.1.1\OgreMain\include" INCLUDEPATH += "E:\_Projects\Temp\ogre-13.1.1\Components\Bites\include" INCLUDEPATH += "E:\_Projects\Temp\ogre-13.1.1\Components\RTShaderSystem\include" LIBS += -L"E:\_Projects\Temp\ogre-13.1.1\dist\lib" #LIBS += -lCodec_STBIStatic -lOgreBitesStatic -lOgreMainStatic -lOgreRTShaderSystemStatic -lPlugin_ParticleFXStatic LIBS += -lDefaultSamples -lOgreBitesStatic -lRenderSystem_GL3PlusStatic -lOgreGLSupportStatic -lOgreMeshLodGeneratorStatic -lOgreOverlayStatic -lOgrePagingStatic -lOgrePropertyStatic -lOgreRTShaderSystemStatic -lOgreVolumeStatic -lPlugin_BSPSceneManagerStatic -lPlugin_DotSceneStatic -lPlugin_OctreeSceneManagerStatic -lPlugin_OctreeZoneStatic -lPlugin_ParticleFXStatic -lPlugin_PCZSceneManagerStatic -lRenderSystem_GLES2Static -lRenderSystem_GLStatic -lOgreMainStatic -lOgreTerrainStatic -lCodec_STBIStatic -lzlibstatic LIBS += -L"E:\_Projects\Temp\ogre-13.1.1\dist\Dependencies\lib" LIBS += -lSDL2main -lSDL2.dll -lfreetype -lpugixml LIBS += -lopengl32 -lgdi32 SOURCES += \ main.cpp
-
My first static Release in Ogre3D and Qt Creator: FirstExample_Ogre3D_QtCreator.zip (8.83 MB)
The BasicTutorial1.cpp example loads the "ogrehead.mesh". In order to load models you have to set up the "resources.cfg" file:
resources.cfg
[Models]
FileSystem=.\main.cpp
#include "Ogre.h" #include "OgreApplicationContext.h" #include "OgreInput.h" #include "OgreRTShaderSystem.h" #include <iostream> using namespace Ogre; using namespace OgreBites; class BasicTutorial1 : public ApplicationContext , public InputListener { public: BasicTutorial1(); virtual ~BasicTutorial1() {} void setup(); bool keyPressed(const KeyboardEvent& evt); }; BasicTutorial1::BasicTutorial1() : ApplicationContext("OgreTutorialApp") { } void BasicTutorial1::setup() { // do not forget to call the base first ApplicationContext::setup(); addInputListener(this); // get a pointer to the already created root Root* root = getRoot(); SceneManager* scnMgr = root->createSceneManager(); // register our scene with the RTSS RTShader::ShaderGenerator* shadergen = RTShader::ShaderGenerator::getSingletonPtr(); shadergen->addSceneManager(scnMgr); // -- tutorial section start -- //! [turnlights] scnMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); //! [turnlights] //! [newlight] Light* light = scnMgr->createLight("MainLight"); SceneNode* lightNode = scnMgr->getRootSceneNode()->createChildSceneNode(); lightNode->attachObject(light); //! [newlight] //! [lightpos] lightNode->setPosition(20, 80, 50); //! [lightpos] //! [camera] SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode(); // create the camera Camera* cam = scnMgr->createCamera("myCam"); cam->setNearClipDistance(5); // specific to this sample cam->setAutoAspectRatio(true); camNode->attachObject(cam); camNode->setPosition(0, 0, 140); // and tell it to render into the main window getRenderWindow()->addViewport(cam); //! [camera] //! [entity1] Entity* ogreEntity = scnMgr->createEntity("ogrehead.mesh"); //! [entity1] //! [entity1node] SceneNode* ogreNode = scnMgr->getRootSceneNode()->createChildSceneNode(); //! [entity1node] //! [entity1nodeattach] ogreNode->attachObject(ogreEntity); //! [entity1nodeattach] //! [cameramove] camNode->setPosition(0, 47, 222); //! [cameramove] //! [entity2] Entity* ogreEntity2 = scnMgr->createEntity("ogrehead.mesh"); SceneNode* ogreNode2 = scnMgr->getRootSceneNode()->createChildSceneNode(Vector3(84, 48, 0)); ogreNode2->attachObject(ogreEntity2); //! [entity2] //! [entity3] Entity* ogreEntity3 = scnMgr->createEntity("ogrehead.mesh"); SceneNode* ogreNode3 = scnMgr->getRootSceneNode()->createChildSceneNode(); ogreNode3->setPosition(0, 104, 0); ogreNode3->setScale(2, 1.2, 1); ogreNode3->attachObject(ogreEntity3); //! [entity3] //! [entity4] Entity* ogreEntity4 = scnMgr->createEntity("ogrehead.mesh"); SceneNode* ogreNode4 = scnMgr->getRootSceneNode()->createChildSceneNode(); ogreNode4->setPosition(-84, 48, 0); ogreNode4->roll(Degree(-90)); ogreNode4->attachObject(ogreEntity4); //! [entity4] // -- tutorial section end -- } bool BasicTutorial1::keyPressed(const KeyboardEvent& evt) { if (evt.keysym.sym == SDLK_ESCAPE) { getRoot()->queueEndRendering(); } return true; } int main(int argc, char **argv) { try { BasicTutorial1 app; app.initApp(); app.getRoot()->startRendering(); app.closeApp(); } catch (const std::exception& e) { std::cerr << "Error occurred during execution: " << e.what() << '\n'; return 1; } return 0; }
-
I did not make "mingw32-make install" after "mingw32-make". I set CMAKE_INSTALL_PREFIX to install path in "CMake GUI". After the "mingw32-make install" command all content will be in one place:
the .pro is more clear:
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE" INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites" INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem" LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib" LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib\OGRE" LIBS += -lOgreBitesStatic -lRenderSystem_GL3PlusStatic -lOgreGLSupportStatic -lOgreMeshLodGeneratorStatic -lOgreOverlayStatic -lOgrePagingStatic -lOgrePropertyStatic -lOgreRTShaderSystemStatic -lOgreVolumeStatic -lPlugin_BSPSceneManagerStatic -lPlugin_DotSceneStatic -lPlugin_OctreeSceneManagerStatic -lPlugin_OctreeZoneStatic -lPlugin_ParticleFXStatic -lPlugin_PCZSceneManagerStatic -lRenderSystem_GLES2Static -lRenderSystem_GLStatic -lOgreMainStatic -lOgreTerrainStatic -lCodec_STBIStatic -lzlibstatic LIBS += -lSDL2main -lSDL2.dll -lfreetype -lpugixml LIBS += -lopengl32 -lgdi32