Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Demo: Integrating OpenSceneGraph with Qt Quick
QtWS25 Last Chance

Demo: Integrating OpenSceneGraph with Qt Quick

Scheduled Pinned Locked Moved 3rd Party Software
osgosgearthopenscenegraphquickqml
20 Posts 6 Posters 28.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • podsvirovP Offline
    podsvirovP Offline
    podsvirov
    wrote on last edited by podsvirov
    #1

    Screen shot

    osgQtQuick:screen

    Code fragment (QML)

    import QtQuick 2.1
    import QtQuick.Controls 1.0
    import osgQtQuick 1.0
    
    ...
    
    OSGNodeFile {
    	id: cessnaNode
    	source: "cessnafire.osg"
    }
    
    OSGViewport {
    	id: fullview
    	anchors.fill: parent
    	sceneData: cessnaNode
    	color: "transparent"
    	opacity: 0.999
    	mode: OSGViewport.Buffer
    }
    
    ...
    

    Download

    • Source code
      osgqtquick-d835c61.tar.gz

    • Or you can try to get the code via git:

      git clone git://podsvirov.pro/osg/osgqtquick.git

    Dependencies

    For this demo, I used:

    • Qt 5.1
    • OpenSceneGraph 3.2.0
    1 Reply Last reply
    1
    • R Offline
      R Offline
      rooi
      wrote on last edited by
      #2

      Great demo!
      After some work I managed to run an exe build with vs2008. I just started working with Qt. I was wondering if it is possible to run it in qt creator -> designer as well. If so, could you please give some pointers on how to get it to work?

      Thanks!

      1 Reply Last reply
      0
      • podsvirovP Offline
        podsvirovP Offline
        podsvirov
        wrote on last edited by
        #3

        I understand that you already have the binaries compiled for windows with vs2008:

        • OpenSceneGraph 3.2.0;
        • Qt 5.1;
        • and osgQtQuick.exe compoled from "source code (in format: tar.gz)":http://git.podsvirov.pro/?p=osg/osgqtquick.git;a=snapshot;h=d835c61f8970d95552a1fc23e8d0f81f28010c1c;sf=tgz

        This demo uses two 3d-models dumptruck.osg and cessnafire.osg from OpenSceneGraph Data package (can be downloaded from "github":https://github.com/openscenegraph/osg-data). You should set the environment variable OSG_FILE_PATH to path_to/osg-data.
        Now you can run osgQtQuick.exe.

        1 Reply Last reply
        0
        • podsvirovP Offline
          podsvirovP Offline
          podsvirov
          wrote on last edited by
          #4

          I do not like VisualStudio.
          Demo I wrote and build in Qt Creator with CMake project.
          I use MinGW 4.8 32bit in Windows 7.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rooi
            wrote on last edited by
            #5

            Ah Thanks for you help Konstantin! I was not aware that you can use cmake with qt creator.

            Maybe you could help me with another thing I tried with your demo. I tried to load an .earth file from the osgEarth kit, but it doesn't work very well. I can see that is loads the earth file, but something seems to go wrong with the rendering to texture. All textures that are shown are replaced by the osgEarth terrain texture. Also the following errors are displayed:

            QSGRenderer: attribute 6 is enabled, this can lead to memory corruption and crashes.
            QSGRenderer: attribute 7 is enabled, this can lead to memory corruption and crashes.

            My initiall guess is that a latter opengl version (4.3) should be used, but how can you indicate which version is used in your example? Sean Harmers post give some indication, but, as I'm quite new to Qt, I can't seem to implement it: http://www.kdab.com/opengl-in-qt-5-1-part-1/

            What do you think? Could the opengl version cause this problem? If so, could you please give some pointers on how to make it work in your demo? Of course, any other thought are very well appreciated!

            Thanks again for your great demo and your help!

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rooi
              wrote on last edited by
              #6

              Hi,

              I found out how to set the opengl version, but unfortunatly it did not solve the problem. Maybe someone has other suggestions on what is going on?

              This is how I set the opengl version by the way. I did not know about the CombatibilityProfile that has to be set for QtQuick.

              QSurfaceFormat format;
              format.setDepthBufferSize( 24 );
              format.setMajorVersion( 4 );
              format.setMinorVersion( 3 );
              format.setSamples( 4 );
              format.setProfile( QSurfaceFormat::CompatibilityProfile );
              view.setFormat(format);

              1 Reply Last reply
              0
              • podsvirovP Offline
                podsvirovP Offline
                podsvirov
                wrote on last edited by
                #7

                I am also interested osgEarth project.
                But I have not checked his work in the context of Qt Quick (Qt 5).
                I hope to attend to it in the future (but still do not know when exactly).
                I used osgEarth with widgets (osgQt) - try them for first.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rooi
                  wrote on last edited by
                  #8

                  Thanks for your reply Konstantin.

                  With the help of the osgEarth guys I think I've figured it out.
                  When I change the frame function as such it seems to work. Maybe you could review it and include it in the demo?

                  Thanks again!

                  void frame() {
                      if (!compositeViewer.valid()) return;
                  
                      // Qt bug!?
                      QOpenGLContext::currentContext()->functions()->glUseProgram(0);
                  
                      /* save current OpenGL state  */
                      glPushAttrib(GL_TEXTURE_BIT|GL_LIGHTING_BIT|GL_SCISSOR_BIT|GL_STENCIL_BUFFER_BIT);
                  
                      //char* version = (char*)glGetString(GL_VERSION);
                  
                      compositeViewer->frame();
                  
                      // qpainter uses vertex attribs 3,4,5 so we need to explicitly disable them:
                      QOpenGLContext::currentContext()->functions()->glDisableVertexAttribArray(3); 
                      QOpenGLContext::currentContext()->functions()->glDisableVertexAttribArray(4); 
                      QOpenGLContext::currentContext()->functions()->glDisableVertexAttribArray(5); 
                      QOpenGLContext::currentContext()->functions()->glDisableVertexAttribArray(6); 
                      QOpenGLContext::currentContext()->functions()->glDisableVertexAttribArray(7); 
                  
                      // qpainter requires depth testing to be off 
                      glDisable(GL_DEPTH_TEST) ;
                  
                      // not sure if this is required; osg changes this when using textures so I reset it to default 
                      glPixelStorei(GL_UNPACK_ALIGNMENT,4); 
                  
                      glPopAttrib();
                  
                  }
                  
                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    cmannett85
                    wrote on last edited by
                    #9

                    Hi,
                    In QuickWindowViewer::Hidden::frame(), the call to QOpenGLContext::currentContext() is returning null for me. The osgviewer and Qt's QML examples work perfectly well, and my machine supports FBOs (OpenGL v3.0) - any ideas why a context couldn't be created?

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      cmannett85
                      wrote on last edited by
                      #10

                      I found the problem, the signal/slot connection to the failing method:

                      @connect(window, SIGNAL(beforeRendering()), this, SLOT(frame()));@

                      It should be specified as a Qt::DirectConnection as noted in the "QQuickWindow docs":http://qt-project.org/doc/qt-5.0/qtquick/qquickwindow.html#exposure-and-visibility - "Warning: As signals related to rendering might be emitted from the rendering thread, connections should be made using Qt::DirectConnection."

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        rooi
                        wrote on last edited by
                        #11

                        Hi Konstantin,

                        I recently got some more time to look into your project again. As I stated before I like the way you integrate osg and qt/qml.

                        I tried to extent the functionality by adding some osg pickers to allow identifying the name and type of a node underneath the mouse. This seems to work initially, but unfortunatly it doesn't after a resize of the window.

                        Do you have any idea why this occurs? My guess is that something does not get the new window size after a resize, but which object? Hopefully you could give me another pointer to try and get this fixed.

                        Thank you very much!

                        Rooi

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          rooi
                          wrote on last edited by
                          #12

                          Hi,

                          I managed to get the picker to work by doing the following:

                          Add the following lines to updateViewport()
                          QSize size(quickItem->boundingRect().size().toSize());
                          if(view->getCamera()->getGraphicsContext())
                          view->getCamera()->getGraphicsContext()->resized( 0, 0, size.width(), size.height() );

                          Thanks.

                          V 1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            alydev
                            wrote on last edited by
                            #13

                            Is someone can send me the demo ? I can't download it...

                            1 Reply Last reply
                            0
                            • podsvirovP Offline
                              podsvirovP Offline
                              podsvirov
                              wrote on last edited by
                              #14

                              I am sorry, but the link to the archive is not working.
                              You can try to get the code via git:
                              @
                              git clone git://podsvirov.pro/osg/osgqtquick.git
                              @

                              1 Reply Last reply
                              0
                              • podsvirovP Offline
                                podsvirovP Offline
                                podsvirov
                                wrote on last edited by
                                #15

                                Good news: a link to a screenshot and the source code in the archive is working again!

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  anu.rastogi
                                  wrote on last edited by
                                  #16

                                  Hi Konstantin,

                                  Sub: enable multisampling

                                  Your example is really well done, Thanks. Now I want to enable multisampling, but I can not figure out how to enable it. I want to use the buffer mode.
                                  The QOpenGLFramebufferObjectFormat.setSamples(4) does not seem to work. I don't have a very deep knowledge or osg::GraphicsWindow and its traits. But if you can guide me, I can take a look.

                                  Thanks a lot,

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    anu.rastogi
                                    wrote on last edited by
                                    #17

                                    Hi Konstantin,

                                    Sub: enable multisampling

                                    Your example is really well done, Thanks. Now I want to enable multisampling, but I can not figure out how to enable it. I want to use the buffer mode.
                                    The QOpenGLFramebufferObjectFormat.setSamples(4) does not seem to work. I don't have a very deep knowledge or osg::GraphicsWindow and its traits. But if you can guide me, I can take a look.

                                    Thanks a lot,

                                    1 Reply Last reply
                                    0
                                    • R rooi

                                      Hi,

                                      I managed to get the picker to work by doing the following:

                                      Add the following lines to updateViewport()
                                      QSize size(quickItem->boundingRect().size().toSize());
                                      if(view->getCamera()->getGraphicsContext())
                                      view->getCamera()->getGraphicsContext()->resized( 0, 0, size.width(), size.height() );

                                      Thanks.

                                      V Offline
                                      V Offline
                                      Voya
                                      wrote on last edited by
                                      #18

                                      @rooi
                                      oh I am facing the same problem as you did. when I resize the windows ,it seems that the Qopenglcontext turn to null . so the fbo is initialized failed. using the method you give it does not work . i try to delete the updatafbo it works but the size of texture does not changed any more.

                                      1 Reply Last reply
                                      0
                                      • podsvirovP Offline
                                        podsvirovP Offline
                                        podsvirov
                                        wrote on last edited by JKSH
                                        #19

                                        Meet osgQtQuick 2.0!

                                        1 Reply Last reply
                                        0
                                        • podsvirovP Offline
                                          podsvirovP Offline
                                          podsvirov
                                          wrote on last edited by
                                          #20

                                          Wow! More than 10 000 views :-)
                                          It seems that many who like it!

                                          I repeat: Meet osgQtQuick 2.0!

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved