【发布时间】:2021-10-27 15:22:58
【问题描述】:
我用:
- Qt 5.15.2 MinGW 32-bit Dynamic for Debug build
- Ogre 13.1.1 MinGW 静态构建
有一个名为 ApplicationContextQt 的类可以帮助将 Qt 与 Ogre3D 一起使用,但我有错误:
这个例子很简单:
main.cpp
#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);
};
MyTestApp::MyTestApp() : OgreBites::ApplicationContextQt("OgreTutorialApp")
{
}
bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt)
{
if (evt.keysym.sym == OgreBites::SDLK_ESCAPE)
{
getRoot()->queueEndRendering();
}
return true;
}
void MyTestApp::setup(void)
{
// do not forget to call the base first
OgreBites::ApplicationContextQt::setup();
}
int main(int argc, char *argv[])
{
QGuiApplication qapp(argc, argv);
MyTestApp app;
app.initApp();
app.getRoot()->startRendering();
app.closeApp();
return qapp.exec();
}
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
【问题讨论】:
-
我建议使用 CMake 并让它找出依赖关系,如 here 所述。
-
谢谢。但我想了解为什么我的示例不起作用。
-
也许有人像我一样尝试用“CMake GUI”构建 Ogre3D 并以这种方式与 Qt 一起使用。
-
我在大约一年前尝试过这个,但从未完全让它与
qmake一起工作。虽然这在技术上几乎肯定是可能的(尤其是当您目前只是看到链接错误时)我可以从个人经验中说@InnocentBystander 有一点。我搬到了cmake,之后效果很好。如果有趣的话,我还有一个最小的测试用例示例。 -
我认为 Ogre 不能与 qmake 一起使用。我用 CMake 而不是 qmake 创建了一个新的 Qt 项目。我在 CMakeList.txt 中添加了这一行:
find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG)我添加了一个新变量 OGRE_DIR(OGREConfig.cmake 所在的位置)。我重新打开了 Qt Creator。这个例子有效!