Important: Please read the Qt Code of Conduct -

Integration issues OpenSceneGraph -> QOpenGLWidget, GL context override

  • Hello Qt devs!

    I'm cross posting this from!topic/osg-users/-I2wXtUFzrM where i originally discussed this issue. I am using the OpenSceneGraph library to abstract OpenGL but instanciating my viewport window through the QOpenGLWidget. This is an example code i have generated to explain my issue.

    QtOSGWidget(QWidget* parent = 0)
          : QOpenGLWidget(parent)
            , _mGraphicsWindow(new osgViewer::GraphicsWindowEmbedded( this->x(), this->y(),
                                                                      this->width(), this->height() ) )
            , _mViewer(new osgViewer::Viewer)
          // take care of HDPI screen, e.g. Retina display on Mac
          , m_scale(QApplication::desktop()->devicePixelRatio())
            osg::Group* root = new osg::Group;
            osg::StateSet* rootStateSet = root->getOrCreateStateSet();
            rootStateSet->setMode( GL_DEPTH_TEST, osg::StateAttribute::ON );
            osgText::Text* text = new osgText::Text();
            osg::Geode* drawableText = new osg::Geode;
            osg::Camera* camera = new osg::Camera;
            camera->setViewport( 0, 0, this->width(), this->height() );
            camera->setClearColor( osg::Vec4( 0.9f, 0.9f, 1.f, 1.f ) );
            float aspectRatio = static_cast<float>( this->width()) / static_cast<float>( this->height() );
            camera->setProjectionMatrixAsPerspective( 30.f, aspectRatio, 1.f, 1000.f );
            camera->setGraphicsContext( _mGraphicsWindow );
            osgGA::TrackballManipulator* manipulator = new osgGA::TrackballManipulator;
            manipulator->setAllowThrow( false );
     virtual void paintGL() {
    int main(int argc, char** argv)
        QSurfaceFormat glFormat;
        glFormat.setVersion(3, 3);
        glFormat.setSamples(4); //anti aliasing
        QApplication qapp(argc, argv);
        QMainWindow window;
        QtOSGWidget* widget = new QtOSGWidget(&window);
        return qapp.exec();

    This causes the following effect on text outputs through the OpenGl render window :

    Where you can see a clear pixelating issue on the text output. The main dev of OpenSceneGraph discusses in the topic that it could be related to the OpenGLWidget setting the graphics context overriding the settings OSG provides. What exactly is the OpenGLWidget doing with the GL state and what could cause such pixelation? Any leads to solve this issue is appreciated. Thanks

    Best regards Dan

  • Hello

    Perhaps i posted this in the wrong subforum. Is there a better place for this topic?

    //Regards Dan

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    No you did not, however you might be in a case that nobody encountered here thus the lack of answer.

    In any case, you should provide more information about your setup:

    • Qt version
    • OSG version
    • OS

    A complete minimal compilable example that shows the behaviour.

Log in to reply