Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Integration issues OpenSceneGraph -> QOpenGLWidget, GL context override



  • Hello Qt devs!

    I'm cross posting this from https://groups.google.com/forum/#!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())
    
          {
    
            _mGraphicsWindow->init();
    
    
    
            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();
    
            text->setText("ABRAKADABRA");
    
            text->setCharacterSize(14);
    
            text->setCharacterSizeMode(osgText::Text::CharacterSizeMode::SCREEN_COORDS);
    
            text->setAutoRotateToScreen(true);
    
            text->setColor(osg::Vec4(0,0,0,1));
    
    
    
            osg::Geode* drawableText = new osg::Geode;
    
            drawableText->addDrawable(text);
    
            root->addChild(drawableText);
    
    
    
            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 );
    
    
    
            _mViewer->setCamera(camera);
    
            _mViewer->setSceneData(root);
    
            osgGA::TrackballManipulator* manipulator = new osgGA::TrackballManipulator;
    
            manipulator->setAllowThrow( false );
    
            this->setMouseTracking(true);
    
            _mViewer->setCameraManipulator(manipulator);
    
            _mViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
    
            _mViewer->realize();
    
            
    
    
    
          }
    
    
     virtual void paintGL() {
    
        _mViewer->frame();
    
      }
    
    
    int main(int argc, char** argv)
    
    {
    
        QSurfaceFormat glFormat;
    
        glFormat.setVersion(3, 3);
    
        glFormat.setProfile(QSurfaceFormat::CoreProfile);
    
        glFormat.setSamples(4); //anti aliasing
    
        QSurfaceFormat::setDefaultFormat(glFormat);
    
    
    
        QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
    
    
        QApplication qapp(argc, argv);
    
        QMainWindow window;
    
        QtOSGWidget* widget = new QtOSGWidget(&window);
    
    
    
        window.setCentralWidget(widget);
    
        window.show();
    
    
    
        return qapp.exec();
    
    }
    

    This causes the following effect on text outputs through the OpenGl render window : https://imgur.com/a/S7IsZs5

    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