Back to Blog home

Qt Commercial Support Weekly #4: Mixing OpenGL and QPainter + Qt 4.5.x with Sun Studio 12

Published on Monday November 21, 2011 by Andy Shaw in BlogRoot | Comments

 

As a fair few may already know, it is possible to easily mix painting with OpenGL and QPainter with the help of QPainter::beginNativePainting() and QPainter::endNativePainting().  This enables you to do something like:

 

painter->beginNativePainting();

// opengl painting calls here

painter->endNativePainting();

painter->drawText(50, 50, "This is a test");

 

 

It will render the text after the OpenGL has been rendered.  For the most part this will work fine and will not cause any problems.  However, one thing to watch out for is that if you change any of the GL states after the beginNativePainting() call then this can have an effect on the Qt rendering.  One example is the GL_DEPTH_TEST state. If this is enabled after the beginNativePainting(), then it will cause the text not to be drawn.  This is because Qt does not account for any potential state changes that could have occurred.  Therefore, in order to be sure that it has no adverse effect on the Qt rendering, you need to reset the GL states to be back to what they are.  So you would have something like:

 

 

painter->beginNativePainting();

glEnable(GL_DEPTH_TEST);

// opengl painting calls here

glDisable(GL_DEPTH_TEST);

painter->endNativePainting();

painter->drawText(50, 50, "This is a test");

 

 

This will allow you to have the depth testing in your OpenGL without having it impact the painting done by the QPainter.  There are some other states to watch out for which are covered in the documentation for QPainter::beginNativePainting() at http://doc.qt.nokia.com/qpainter.html#beginNativePainting.

 

Now, to show that we still have love for those Unix platforms out there we recently heard of a build issue in support with using Sun Studio 12 (CC 5.10) with Qt 4.5.x.  Although CC 5.10 is not actually a supported version for Qt 4.5.x and we had the means to do so, we investigated the issue as we want to provide a good service where ever possible for customers.  I am happy to report that we have been able to fix the build issue that was reported, so if you are using Qt 4.5.x with Solaris and would like to get hold of the patch, then please submit a support request via the customer portal and we can make it available to you.  This doesn't mean we can provide official support for Sun Studio 12 with Qt 4.5.x, but from what we can see it is working pretty fine so every little bit helps.

 

Finally, next week, four of the support team members will be in San Francisco for Qt Developer Days 2011, so if you are around there then feel free to pop by. They will be there all days and they are ready to help you out or just to have a chat if you want to say hi.

Subscribe to Our Blog

Stay up to date with the latest marketing, sales and service tips and news.

We are updating our comment system and you could face some issues. Please write to us at feedback@qt.io to report issues/bugs.