Is it possible to use Orge3D 13.1.1 inside of Qt 5.15.2 Widget for static build?

Problems building or running the engine, queries about how to use features etc.
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Is it possible to use Orge3D 13.1.1 inside of Qt 5.15.2 Widget for static build?

Post by 8Observer8 »

Hello,

I want to draw inside of Qt Widget with Ogre3D. But I want to have Qt GUI in the same window.

I made this simple demo in pure OpenGL 3.3 and Qt:
Image

I found this page OgreBites::ApplicationContextQt Class Reference. But I do not understand, can I only create separate window for Ogre3D from Qt application? If I can combine Ogre3D and Qt GUI in the same window, please, give me links on examples. I cannot find any tutorials and examples.
Last edited by 8Observer8 on Fri Oct 29, 2021 4:39 pm, edited 2 times in total.
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I created the "Ogre3DWidget". I tried to build the example below but I have these errors. It seems like I need additional library for ApplicationContextQt. If it is where is it?
ApplicationContextQt_Libs_Errors.png
Ogre3DWidget.h

Code: Select all

#ifndef OGRE3DWIDGET_H
#define OGRE3DWIDGET_H

#include "Ogre.h"
#include <OgreApplicationContextQt.h>
#include "OgreInput.h"
#include "OgreRTShaderSystem.h"

using namespace Ogre;
using namespace OgreBites;


class Ogre3DWidget : public ApplicationContextQt, public InputListener
{
public:
    Ogre3DWidget();
    virtual ~Ogre3DWidget() { }

    void setup();
    bool keyPressed(const KeyboardEvent& evt);
};

#endif // OGRE3DWIDGET_H
Ogre3DWidget.cpp

Code: Select all

#include "Ogre3DWidget.h"

Ogre3DWidget::Ogre3DWidget()
    : ApplicationContextQt("Ogre Widget")
{
}

void Ogre3DWidget::setup()
{
    // do not forget to call the base first
    ApplicationContextQt::setup();
    addInputListener(this);

    // get a pointer to the already created root
    Root* root = getRoot();
    SceneManager* scnMgr = root->createSceneManager();

    ResourceGroupManager rgm;


    // 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 Ogre3DWidget::keyPressed(const KeyboardEvent &evt)
{
    if (evt.keysym.sym == SDLK_ESCAPE)
    {
        getRoot()->queueEndRendering();
    }
    return true;
}
Widget.h

Code: Select all

#ifndef WIDGET_H
#define WIDGET_H

#include <QtWidgets/QWidget>
#include "Ogre3DWidget.h"


class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private:
    Ogre3DWidget _ogre3DWidget;
};
#endif // WIDGET_H
Widget.cpp

Code: Select all

#include "Widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    setWindowTitle("Qt Widget for Ogre3D");
}

Widget::~Widget()
{
}
main.cpp

Code: Select all

#include "Widget.h"

#include <QtWidgets/QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    return a.exec();
}
.pro

Code: Select all

QT       += core gui

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

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    Ogre3DWidget.cpp \
    main.cpp \
    Widget.cpp

HEADERS += \
    Ogre3DWidget.h \
    Widget.h

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I found why I do not have a Qt library:
QT_DIR-NOTFOUND.png
QT_DIR-NOTFOUND.png (10.52 KiB) Viewed 8912 times
What I need to write there?

Is it good:
QT_DIR.png
QT_DIR.png (3.25 KiB) Viewed 8912 times
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I have the error:
[ 97%] Built target DefaultSamples
[ 97%] Building CXX object Samples/Browser/CMakeFiles/SampleBrowser.dir/src/main.cpp.obj
mingw32-make[2]: *** No rule to make target 'Dependencies/lib/IrrXML.lib', needed by 'bin/SampleBrowser.exe'. Stop.
mingw32-make[1]: *** [CMakeFiles\Makefile2:1275: Samples/Browser/CMakeFiles/SampleBrowser.dir/all] Error 2
mingw32-make: *** [Makefile:155: all] Error 2
I will try to rebuild it without samples.
User avatar
nuke
Halfling
Posts: 72
Joined: Wed Oct 01, 2014 1:16 am
Location: Crimea
x 5

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by nuke »

Прикольная у тебя ёлочка получилась в первом посте! :D
RUS -> ENG: Cool Christmas tree in the first post! :D
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I made two big mistakes:
  • I did not add Qt5 to PATH. I had Qt6 in PATH
  • I did not make "mingw32-make install" after "mingw32-make".
I added Qt5 to PATH:
PATH.png
PATH.png (2.09 KiB) Viewed 8874 times
CMake found paths to Qt5:
Qt5Paths.png
Qt5Paths.png (11.02 KiB) Viewed 8874 times
Samples installed successfully. "include" and "lib" and so on are in one folder:
AllFoldersInOnePlace.png
AllFoldersInOnePlace.png (1.49 KiB) Viewed 8874 times
I have the "libOgreBitesQtStatic.a" library now.
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I think ApplicationContextQt is in libOgreBitesQtStatic.a

But I have these errors:
Attachments
OgreBites20ApplicationContextQtE.png
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

How to know where _imp___ZTVN9OgreBites20ApplicationContextQtE is placed?
E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites\OgreApplicationContextQt.h:41: error: undefined reference to `_imp___ZTVN9OgreBites20ApplicationContextQtE'
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I included all (21) libraries:

Code: Select all

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 += -lOgreBitesQtStatic
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
This error:
E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites\OgreApplicationContextQt.h:41: error: undefined reference to `_imp___ZTVN9OgreBites20ApplicationContextQtE'
points to this line:

Code: Select all

class _OgreBitesQtExport ApplicationContextQt : public QObject, public ApplicationContextBase
in this header file:
E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites\OgreApplicationContextQt.h
What additional information should I show you?
Attachments
OgreBites20ApplicationContextQtE.png
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by paroj »

switching the bootstrap sample works for me like this:
https://github.com/paroj/ogre/commit/b2 ... 729304d346

your error seems to indicate that some Qt MOC stuff is missing. Maybe it is a separate lib when doing a static build.
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I tried to run the bootstrap sample but I have the same errors:

main.cpp

Code: Select all

#include "Ogre.h"
#include "OgreApplicationContextQt.h"
#include <QGuiApplication>

class MyTestApp : public OgreBites::ApplicationContextQt, public OgreBites::InputListener
{
public:
    MyTestApp();
    void setup();
    bool keyPressed(const OgreBites::KeyboardEvent& evt);
};

//! [constructor]
MyTestApp::MyTestApp() : OgreBites::ApplicationContextQt("OgreTutorialApp")
{
}
//! [constructor]

//! [key_handler]
bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt)
{
    if (evt.keysym.sym == OgreBites::SDLK_ESCAPE)
    {
        getRoot()->queueEndRendering();
    }
    return true;
}
//! [key_handler]

//! [setup]
void MyTestApp::setup(void)
{
    // do not forget to call the base first
    OgreBites::ApplicationContextQt::setup();

    // register for input events
    addInputListener(this);

    // get a pointer to the already created root
    Ogre::Root* root = getRoot();
    Ogre::SceneManager* scnMgr = root->createSceneManager();

    // register our scene with the RTSS
    Ogre::RTShader::ShaderGenerator* shadergen = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
    shadergen->addSceneManager(scnMgr);

    // without light we would just get a black screen
    Ogre::Light* light = scnMgr->createLight("MainLight");
    Ogre::SceneNode* lightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
    lightNode->setPosition(0, 10, 15);
    lightNode->attachObject(light);

    // also need to tell where we are
    Ogre::SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
    camNode->setPosition(0, 0, 15);
    camNode->lookAt(Ogre::Vector3(0, 0, -1), Ogre::Node::TS_PARENT);

    // create the camera
    Ogre::Camera* cam = scnMgr->createCamera("myCam");
    cam->setNearClipDistance(5); // specific to this sample
    cam->setAutoAspectRatio(true);
    camNode->attachObject(cam);

    // and tell it to render into the main window
    getRenderWindow()->addViewport(cam);

    // finally something to render
    Ogre::Entity* ent = scnMgr->createEntity("Sinbad.mesh");
    Ogre::SceneNode* node = scnMgr->getRootSceneNode()->createChildSceneNode();
    node->attachObject(ent);
}
//! [setup]

//! [main]
int main(int argc, char *argv[])
{
    QGuiApplication qapp(argc, argv);
    MyTestApp app;
    app.initApp();
    app.getRoot()->startRendering();
    app.closeApp();
    return qapp.exec();
}
//! [main]
.pro

Code: Select all

QT       += core gui

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 += -lOgreBitesQtStatic
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

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp

HEADERS +=

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
Attachments
OgreBites20ApplicationContextQtE.png
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

your error seems to indicate that some Qt MOC stuff is missing. Maybe it is a separate lib when doing a static build.
I use Qt Dynamic for debugging and Qt Static for Releases.

I tried to build the Bootstrap sample to static release. I have another errors:
Attachments
002_QtStaticRelease.png
001_QtStaticRelease.png
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I think that Ogre cannot work with qmake and I should use CMake instead of qmake::
Attachments
QtCMake.png
QtCMake.png (5.45 KiB) Viewed 8765 times
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I look at this instruction but I do not understand it: https://ogrecave.github.io/ogre/api/lat ... html#cmake

Where should I copy this line:
find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG)
I have these project files:
BootstrapCMakeQt5Cpp.png
BootstrapCMakeQt5Cpp.png (9.49 KiB) Viewed 8765 times
Should I copy it to CMakeLists.txt? I added OGRE_DIR:
OGRE_DIR.png
OGRE_DIR.png (2.99 KiB) Viewed 8765 times
But when I copy the find_package I have the error:
E:\_Projects\Ogre3D\BootstrapCMakeQt5Cpp\CMakeLists.txt:5: error: Could not find a package configuration file provided by "OGRE" with any of the following names: OGREConfig.cmake ogre-config.cmake Add the installation prefix of "OGRE" to CMAKE_PREFIX_PATH or set "OGRE_DIR" to a directory containing one of the above files. If "OGRE" provides a separate development package or SDK, be sure it has been installed.
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I solve the problem in the message above! I just reopened Qt Creator:
BootstrapCMakeQt5Cpp2.png
BootstrapCMakeQt5Cpp2.png (7.98 KiB) Viewed 8762 times
-- Found OGRE
-- static : ON
-- components : Bites;MeshLodGenerator;Overlay;Paging;Property;RTShaderSystem;Terrain;Volume
-- plugins : Plugin_BSPSceneManager;Plugin_OctreeSceneManager;Plugin_PCZSceneManager;Plugin_ParticleFX;RenderSystem_GL;RenderSystem_GLES2;RenderSystem_GL3Plus;Codec_STBI
-- media : E:/ProgramFiles/ogre-13.1.1/Media
-- Configuring done
-- Generating done
-- Build files have been written to: E:/_Projects/Ogre3D/build-BootstrapCMakeQt5Cpp-Desktop_Qt_5_15_2_MinGW_32_bit-Debug
Elapsed time: 00:02.
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

How to add "libOgreBitesQtStatic.a" to my project?
find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG)
I see that "libOgreBitesStatic.a" called like Bites, "libOgreRTShaderSystemStatic.a" called like RTShaderSystem. But how called "libOgreBitesQtStatic.a"? I tried to make this:
find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem BitesQt CONFIG)
But "Component 'BitesQt' is required but not found".
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

Please, send me what I should to copy in CMakeLists.txt instead of:
# specify which components you need.
# The CONFIG flag makes sure you get OGRE instead of OGRE-next
find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG)

# add the source files as usual
add_executable(0_Bootstrap Bootstrap.cpp)

# this also sets the includes and pulls third party dependencies
target_link_libraries(0_Bootstrap OgreBites OgreRTShaderSystem)
to run this example with "OgreApplicationContextQt": https://github.com/paroj/ogre/commit/b2 ... 729304d346
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I have default CMakeLists.txt from Qt and I edited two last lines:

Code: Select all

find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG)
target_link_libraries(BootstrapCMakeQt5Cpp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets OgreBites OgreRTShaderSystem)

Code: Select all

cmake_minimum_required(VERSION 3.5)

project(BootstrapCMakeQt5Cpp LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check https://doc.qt.io/qt/deployment-android.html for more information.
# They need to be set before the find_package( ...) calls below.

#if(ANDROID)
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
#endif()

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)

set(PROJECT_SOURCES
        main.cpp
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(BootstrapCMakeQt5Cpp
        ${PROJECT_SOURCES}
    )
else()
    if(ANDROID)
        add_library(BootstrapCMakeQt5Cpp SHARED
            ${PROJECT_SOURCES}
        )
    else()
        add_executable(BootstrapCMakeQt5Cpp
            ${PROJECT_SOURCES}
        )
    endif()
endif()

find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG)
target_link_libraries(BootstrapCMakeQt5Cpp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets OgreBites OgreRTShaderSystem)
But I have error here:

Code: Select all

    else()
        add_executable(BootstrapCMakeQt5Cpp
            ${PROJECT_SOURCES}
        )
    endif()
CMake Error at CMakeLists.txt:44 (add_executable):
Target "BootstrapCMakeQt5Cpp" links to target "ZLIB::ZLIB" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?


CMake Error at CMakeLists.txt:44 (add_executable):
Target "BootstrapCMakeQt5Cpp" links to target "SDL2::SDL2" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
Why? I read here: https://ogrecave.github.io/ogre/api/lat ... html#cmake that:
These settings already include any third party libraries the Components depends on (e.g. SDL) - nothing more to do.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by paroj »

8Observer8 wrote: Wed Oct 27, 2021 10:59 pm Please, send me what I should to copy in CMakeLists.txt instead of:
# specify which components you need.
# The CONFIG flag makes sure you get OGRE instead of OGRE-next
find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG)

# add the source files as usual
add_executable(0_Bootstrap Bootstrap.cpp)

# this also sets the includes and pulls third party dependencies
target_link_libraries(0_Bootstrap OgreBites OgreRTShaderSystem)
to run this example with "OgreApplicationContextQt": https://github.com/paroj/ogre/commit/b2 ... 729304d346
https://github.com/paroj/ogre/commit/b2 ... b3c8edcR17
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by paroj »

8Observer8 wrote: Wed Oct 27, 2021 11:12 pm
CMake Error at CMakeLists.txt:44 (add_executable):
Target "BootstrapCMakeQt5Cpp" links to target "ZLIB::ZLIB" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?


CMake Error at CMakeLists.txt:44 (add_executable):
Target "BootstrapCMakeQt5Cpp" links to target "SDL2::SDL2" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
Why? I read here: https://ogrecave.github.io/ogre/api/lat ... html#cmake that:
These settings already include any third party libraries the Components depends on (e.g. SDL) - nothing more to do.
this likely only works for shared libs - for static libs you might have to do what cmake tells you
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I added SDL2::SDL2 and ZLIB::ZLIB here:

Code: Select all

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(BootstrapCMakeQt5Cpp
        ${PROJECT_SOURCES}
    )
else()
    if(ANDROID)
        add_library(BootstrapCMakeQt5Cpp SHARED
            ${PROJECT_SOURCES}
        )
    else()
        find_package(OGRE REQUIRED COMPONENTS CONFIG)

        add_executable(BootstrapCMakeQt5Cpp
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(BootstrapCMakeQt5Cpp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets OgreBitesQt OgreRTShaderSystem SDL2::SDL2 ZLIB::ZLIB)
But why do I see this message:
CMake Error at CMakeLists.txt:46 (add_executable):
Target "BootstrapCMakeQt5Cpp" links to target "SDL2::SDL2" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?


CMake Error at CMakeLists.txt:46 (add_executable):
Target "BootstrapCMakeQt5Cpp" links to target "ZLIB::ZLIB" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

How to add zlib and SDL2 to CMakeLists.txt?
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

Can I use SDL2 from Ogre installation or I must write my own "sdl2-config.cmake" for static build?
8Observer8
Halfling
Posts: 78
Joined: Sat Feb 29, 2020 12:29 am
x 2

Re: Is it possible to use Orge3D inside of Qt Widget?

Post by 8Observer8 »

I set everything. Why is it not work?

Code: Select all

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(BootstrapCMakeQt5Cpp
        ${PROJECT_SOURCES}
    )
else()
    if(ANDROID)
        add_library(BootstrapCMakeQt5Cpp SHARED
            ${PROJECT_SOURCES}
        )
    else()
        add_executable(BootstrapCMakeQt5Cpp
            ${PROJECT_SOURCES}
        )
    endif()
endif()

set(SDL2_LIBRARIES "${OGRE_DIR}/lib/libSDL2.dll.a;${OGRE_DIR}/lib/libSDL2main.a")
string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)

find_package(OGRE SDL2 REQUIRED COMPONENTS CONFIG)
target_link_libraries(BootstrapCMakeQt5Cpp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets OgreBitesQt OgreRTShaderSystem SDL2::SDL2 ZLIB::ZLIB)
Why do I see this message:
CMake Error at CMakeLists.txt:44 (add_executable):
Target "BootstrapCMakeQt5Cpp" links to target "SDL2::SDL2" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
Post Reply