QGLBuilder and QGLSceneNode help



  • How do I use QGLBuilder and QGLSceneNode to add multiple objects to a scene? When I try the code below app expectedly quits...

    QGLBuilder builder;
    QGLSceneNode *node;
    builder << QGL::Faceted;
    builder << QGLSphere(2,4);
    root = builder.finalizedSceneNode();
    builder << QGLCube();
    node = builder.finalizedSceneNode();
    root->addNode(node);

    Thanks.



  • ...after further reading the following produces a blank screen:
    @
    CubeView::CubeView(QWindow *parent)
    : QGLView(parent)
    {
    // here a top level node for the app is created, and parented to the view
    topNode = new QGLSceneNode(this);

    QGLBuilder b1;
    // build geometry
    b1 << QGL::Faceted;
    b1 << QGLSphere(2,4);
    
    thing = b1.finalizedSceneNode();
    
    // does a QObject::setParent() to manage memory, and also adds to the scene
    // graph, so no need to call topNode->addNode(thing)
    thing->setParent(topNode);
    
    QGLBuilder b2;
    // build more geometry
    b2 << QGLCube();
    
    anotherThing = b2.finalizedSceneNode();
    
    // again parent on get addNode for free
    anotherThing->setParent(topNode);
    

    @
    }



  • ...working now, changed CubeView::paintGL to only draw child nodes for now...

    @
    void CubeView::paintGL(QGLPainter *painter)
    {
    painter->setStandardEffect(QGL::LitMaterial);
    painter->setFaceColor(QGL::AllFaces, QColor(170, 202, 0));

    painter->modelViewMatrix().rotate(45.0f,1.0f,1.0f,1.0f);
    thing->draw(painter);
    
    QMatrix4x4 mat;
    mat.translate( 2.0f, 0.0f, -2.0f);
    anotherThing->setLocalTransform(mat);
    anotherThing->draw(painter);
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.