Article directory
- Compilation and use of libQGLViewer
-
- 1 Introduction
- 2 libQGLViewer development environment construction
-
- 2.1 Download and installation of Qt Creator
- 2.2 Download and compile libQGLViewer
- 2.3 Install the QGLViewer control plug-in for Qt Designer (optional)
- 2.3 Some issues about the QGLViewer control plug-in of Qt Designer
- 3 Call it in your own project
- 4 Summary
Compilation and use of libQGLViewer
1 Foreword
Test environment:
- Windows 10
- Qt Creator
- libQGLViewer-2.9.1
2 libQGLViewer development environment construction
2.1 Qt Creator download and installation
In fact, VS can also be developed, but here we use Qt Creator
Reference tutorial: Building a Qt development environment under WIndows – Qt and Qt Creator installation and configuration.
2.2 Download and compile libQGLViewer
Source code download address: GillesDebunne/libQGLViewer.
http://www.libqglviewer.com I don’t know why this website suddenly cannot be accessed. Fortunately, we can go directly to the project’s Github creation library to download the source code.
It needs to be mentioned here that the documents in the project source code branch (
doc
folder) are incomplete. For complete documents, download thegh-pages
branch and then merge the contents intodoc
folder.
Use Qt Creator to open libQGLViewer/QGLViewer/QGLViewer.pro
to load the project.
Then click the small hammer in the lower left corner to complete the construction. The build is successful and two dll files are obtained: QGLViewer2.dll
and QGLViewerd2.dll
.
Next, copy these two dynamic libraries to C:\Windows\System32
. Finish.
Of course, the build process wasn’t all smooth sailing (it took a beating). I encountered the following error:
I went to browse the issues in the github repository, and sure enough, someone also encountered the same problem (Compiling issues in Qt5.12.12 Ubuntu20.04 · Issue #72). The solution given by a big guy below is as follows:
It probably means that when this version of the code encounters a multi-screen display system, we need to manually select a specific screen. I also specifically checked the source code of version 2.8.0 and found that this part of the code did not introduce the QScreen
header file in version 2.8.0, which is why version 2.8.0 does not report this error.
Based on the above solution, we modify the parts of the two source files qglviewer.cpp and saveSnapshot.cpp that involve calling the screen()
function :
void QGLViewer::setCamera(Camera *const camera) {<!-- --> if (!camera) return; QScreen *screen = QGuiApplication::primaryScreen(); // Disconnect current camera from this viewer. disconnect(this->camera()->frame(), SIGNAL(manipulated()), this, SLOT(update())); disconnect(this->camera()->frame(), SIGNAL(spun()), this, SLOT(update())); //disconnect(screen(), SIGNAL(physicalDotsPerInchChanged(qreal)), this->camera(), SLOT(setDevicePixelRatio(qreal))); disconnect(screen, SIGNAL(physicalDotsPerInchChanged(qreal)), this->camera(), SLOT(setDevicePixelRatio(qreal))); connectAllCameraKFIInterpolatedSignals(false); camera_ = camera; camera->setSceneRadius(sceneRadius()); camera->setSceneCenter(sceneCenter()); camera->setScreenWidthAndHeight(width(), height()); // camera->setDevicePixelRatio(screen()->devicePixelRatio()); camera->setDevicePixelRatio(screen->devicePixelRatio()); // Connect camera frame to this viewer. connect(camera->frame(), SIGNAL(manipulated()), SLOT(update())); connect(camera->frame(), SIGNAL(spun()), SLOT(update())); // connect(screen(), SIGNAL(physicalDotsPerInchChanged(qreal)), camera, SLOT(setDevicePixelRatio(qreal))); connect(screen, SIGNAL(physicalDotsPerInchChanged(qreal)), camera, SLOT(setDevicePixelRatio(qreal))); connectAllCameraKFIInterpolatedSignals(); previousCameraZClippingCoefficient_ = this->camera()->zClippingCoefficient(); }
bool QGLViewer::saveImageSnapshot(const QString & amp;fileName) {<!-- --> static ImageInterface *imageInterface = nullptr; QScreen *screen = QGuiApplication::primaryScreen(); //qreal devicePixelRatio = screen()->devicePixelRatio(); qreal devicePixelRatio = screen->devicePixelRatio(); qreal dipWidth = devicePixelRatio * width(); qreal dipHeight = devicePixelRatio * height(); ...
There will be no problem when building again.
2.3 Install the QGLViewer control plug-in for Qt Designer (optional)
Use Qt Creator to open libQGLViewer/designerPlugin/designerPlugin.pro
to load the project, and use Xiaohammer to build the project. Note that you need to switch to release to build.
After the build is completed, the qglviewerplugin.dll
dynamic library file will be generated in the libQGLViewer/build-designerPlugin-Desktop_5_13_1_MinGW_64_bit-Release/release
directory.
Next, copy this dynamic library file to the $QTDIR\plugins\designer
directory.
Then according to the official tutorial, you also need to copy QGLViewer2.dll
to the $QTDir\bin
directory.
Then double-click to open the designer.exe
program in the $QTDir\bin
directory to enter the Qt Designer interface. Found that the plug-in was installed successfully.
2.3 Some issues about the QGLViewer control plug-in of Qt Designer
The plug-in installed above can only be used in the designer.exe
program in the $QTDir\bin
directory, which means it cannot be used in the designer in Qt Creator.
For specific reasons, see: https://blog.csdn.net/weixin_43207311/article/details/121704484.
The solution is roughly: check your own version from Qt Creator’s help “About Qt Creator”, and just copy the corresponding version of the plug-in library to “xxx\Tools\QtCreator\bin\plugins\designer” Download it, refresh it again and it will be ok.
Because it was found that it was compiled with MSVC 2017, 32 bit, and my compiler only has MinGW64 installed, so I have to trouble myself a little, which is rare.
3 Call in your own project
Logically speaking, now we use Qt Creator to open .pro
in the example project in the libQGLViewer/examples
directory, load the example, and then we can run it perfectly and see the effect. .
But now we want to create a new project and import libQGLViewer as a third-party library into our own project.
First, in order to facilitate the management of library files, we first create new include and lib folders in the libQGLViewer
directory. After finishing, the structure of the two folders is as follows:
├─include │ └─QGLViewer │ │ camera.cpp │ │ camera.h │ │ config.h │ │ constraint.cpp │ │ constraint.h │ │ domUtils.h │ │ frame.cpp │ │ frame.h │ │ keyFrameInterpolator.cpp │ │ keyFrameInterpolator.h │ │ manipulatedCameraFrame.cpp │ │ manipulatedCameraFrame.h │ │ manipulatedFrame.cpp │ │ manipulatedFrame.h │ │ mouseGrabber.cpp │ │ mouseGrabber.h │ │ qglviewer.cpp │ │ qglviewer.h │ │ quaternion.cpp │ │ quaternion.h │ │ saveSnapshot.cpp │ │vec.cpp │ │ vec.h │ │ │ └─VRender │ AxisAlignedBox.h │ BackFaceCullingOptimizer.cpp │BSPSortMethod.cpp │ EPSExporter.cpp │Exporter.cpp │Exporter.h │FIGExporter.cpp │ gpc.cpp │gpc.h │ NVector3.cpp │ NVector3.h │ Optimizer.h │ParserGL.cpp │ParserGL.h │ Primitive.cpp │ Primitive.h │ PrimitivePositioning.cpp │ PrimitivePositioning.h │ SortMethod.h │TopologicalSortMethod.cpp │Types.h │Vector2.cpp │Vector2.h │ Vector3.cpp │Vector3.h │VisibilityOptimizer.cpp │VRender.cpp │VRender.h │ └─lib libQGLViewer2.a libQGLViewerd2.a QGLViewer2.dll QGLViewerd2.dll
For the convenience of testing, we directly copy the libQGLViewer/examples/drawLight
folder to any path, and then use Creator to open the .pro
in it to load the project. At this time, if we run it directly, an error will definitely be reported. Next, we modify the drawLight.pro
file:
TEMPLATE = app TARGET = drawLight QT *= xml opengl widgets gui CONFIG + = qt opengl thread # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES + = QT_DEPRECATED_WARNINGS INCLUDEPATH + = G:/MSTIFIY/local/libQGLViewer/include # Change to include folder path LIB_DIR = G:/MSTIFIY/local/libQGLViewer/lib # Change to the lib folder path win32 { # Seems to be needed for Visual Studio with Intel compiler DEFINES *= WIN32 # Use native OpenGL drivers with Qt5.5 # No longer implicit since the ANGLE driver is now an alternative LIBS + = -lopengl32 -lglu32 isEmpty( QGLVIEWER_STATIC ) { CONFIG(debug, debug|release) { LIBS *= -L$${LIB_DIR} -lQGLViewerd2 } else { LIBS *= -L$${LIB_DIR} -lQGLViewer2 } } else { DEFINES *= QGLVIEWER_STATIC CONFIG(debug, debug|release) { LIBS *= $${LIB_DIR}/libQGLViewerd2.a } else { LIBS *= $${LIB_DIR}/libQGLViewer2.a } } } HEADERS = drawLight.h SOURCES = drawLight.cpp main.cpp
Remember to modify the INCLUDEPAT and LIB_DIR variables.
At this time, click Run and the following results will appear. The operation is successful!
4 Summary
Yesterday, I worked all day and my head felt heavy. I went to bed at 23:00 at night. After waking up this morning, I changed a computer and started all over again. It really succeeded, which is quite a sense of accomplishment. Woohoo, matching the environment is really a troublesome thing.