Making Qt and OpenSceneGraph play nice: An addendum
Tags: programming, software
I have written a number of posts about Qt and OpenSceneGraph this year. Starting from how to design a basic widget for OSG, I showed how to extend the widget to enable rectangular selections. In the last post so far, I explained how to do some simple object picking.
In the process of receiving some feedback about these articles, I learned even more about OpenSceneGraph. To ensure that the code and articles remain valid in the future, there are a couple of remaining issues on which I want to expand briefly.
Porting to Microsoft Windows
I do not have much experience in developing for this platform. However, thanks to Andrew
Cunningham, I now know that the program compiles & runs under Microsoft Windows if the selection
rectangle is not drawn. Apparently, QPainter
(which I use for drawing the selection rectangle)
uses “GDI”, which does not mix well with OSG’s OpenGL
rendering.
As a remedy, I made the selection rectangle (as well as the object picking) configurable. Just set
the variables WITH_PICK_HANDLER
and WITH_SELECTION_PROCESSING
accordingly using ccmake
in your
build directory. I hope that I may fix this properly one time.
Porting to OS X
Again, I have only limited experience with this platform. However, I can at least guarantee that the
program compiles and runs reasonable well. I had to install Qt4
using the excellent Homebrew
package manager for OS X. OS X also handles graphics context switches differently
that Linux, which exposed another bug in the program—I had to use makeCurrent()
and
doneCurrent()
in the drawing routines to ensure that the OSG widget is allowed to use the graphics
context.
There are still some glitches, though: The QMdiArea
widgets do not overlap correctly when being
moved. I strongly suspect that this is an issue with Qt and not with OSG (since OSG knows nothing
about the widget geometry). Furthermore, the widgets will not be rendered correctly all the time.
This seems to be caused by OS X switching between two graphics cards.
Unfortunately, I don’t have any definite solutions for this. I will update the program, though, if I find the root cause.
Using Qt 5
To end on a more positive note: The program is now using Qt 5 instead of Qt 4. This at least was
rather easy to achieve and only involved some changes in the CMakeLists.txt
file. Note that I
incremented the minimum required version to 2.8.11 in order to ensure that Qt 5 is being integrated
correctly.
Code
The code is available in a git repository. Please report any bugs or issues.