Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Problem switching between multiple QGLWidgets
Forum Updated to NodeBB v4.3 + New Features

[Solved] Problem switching between multiple QGLWidgets

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.6k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    FreddeB
    wrote on last edited by
    #1

    Hello,

    I have made a small test application to try to figure out how to solve a problem when using two individual GLWidgets sharing the same rendering context.

    I have realized that the best solution when working with multiple glwidgets is to let the glwidgets share the same rendering context through the constructor of QGLWidget otherwise I normally get an exception and the debug output "QGLBuffer::bind: buffer is not valid in the current context"

    In the test I have put two glwidgets together in the main window where I try to add two different models to the glwidgets, one for each widget.

    My problem:

    I have successfully managed to set up the glwidgets and let them share the context but the two glwidgets are showing the same model even if I try to add a different model for the second glwidget.

    Here is the code where I assign the models..

    @

    QGLSceneNode* sgObject = new QGLSceneNode();
    QGLSceneNode* sgObject2 = new QGLSceneNode();

    QString modelsDir = QDir::toNativeSeparators(QDir::homePath());
    QString filter = tr("Models (%1)").arg(QGLAbstractScene::supportedFormats().join(" "));
    QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), modelsDir, filter);
    
    QGLAbstractScene* m_scene = QGLAbstractScene::loadScene(filename, QString(), QString());
    
    
    if(!m_scene){
        QMessageBox msgBox;
        msgBox.setText("Problem att öppna modellen");
        msgBox.setDefaultButton(QMessageBox::Ok);
        msgBox.exec();
        return;
    }
    
    
    sgObject->addNode(m_scene->mainNode());
    
    QString filename2 = QFileDialog::getOpenFileName(this, tr("Open File"), modelsDir, filter);
    
    QGLAbstractScene* m_scene2 = QGLAbstractScene::loadScene(filename, QString(), QString());
    
    
    
    sgObject2->addNode(m_scene2->mainNode());
    
    ui->widget->SetNode(sgObject);
    ui->widget_2->makeCurrent();
    ui->widget_2->SetNode(sgObject2);
    

    @

    Both widgets show the first model loaded.

    Any ideas ? Shall I clear the context in any way before I make the switch ?

    My goal is to get a way where I can see the two glwidgets independent of each other.

    Best Regards
    Fredrik

    Regards
    Fredrik

    1 Reply Last reply
    0
    • F Offline
      F Offline
      FreddeB
      wrote on last edited by
      #2

      Found the problem .. I hope though that somebody have use of my example..

      The problem is that I forgot to change the variable for the second models filename..

      /Fredrik

      Regards
      Fredrik

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        welcome to devnet

        Good to know that you have solved your issue. It is also good to leave your input here for inspiration for others.

        You may want to mark your input as [Solved] in the title. Go to first post at the right under your avatar is a edit field. This allows you to edit this post and the title line.

        I will do for you this time.

        Vote the answer(s) that helped you to solve your issue(s)

        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