[SOLVED] Two Viewports in QGLWidget



  • Hey everyone,
    I'd like to enable support for my Oculus Rift DevKit to my Qt openGL app.
    So far, I've gotten (almost) nowhere.
    Since my viewport is set up in resizeGL(), simply going with two viewports doesn't work - the first one I set up always stays empty, of course.
    I tried to cheat my way around it by simply changing the viewport every time paintGL() is called - which kind of works, but leads to very ugly flickering.
    In the Oculus docs, there is the pseudocode
    @
    // Render Left Eye Half
    SetViewport(0, 0, HResolution/2, VResolution);
    SetProjection(LeftEyeProjectionMatrix);
    RenderScene();
    // Render Right Eye Half
    SetViewport(HResolution/2, 0, HResolution, VResolution);
    SetProjection(RightEyeProjectionMatrix);
    RenderScene();
    @

    But the first call of "RenderScene()" puzzles me. paintGL(), update() or anything like that just crashes my app.
    @
    QGLFormat fmt;
    fmt.setStereo(true);
    setFormat(fmt);
    @

    inside initializeGL() also just crashes.
    How does one enable multiple viewports in a QGLWidget? I couldn't find anything on the net, just an old thread in another forum with basically the same problem, but no one had answered in a long time.
    Thanks in advance!
    Edit:
    I also tried a for loop that takes (almost) all of the paintGL() function and decides via the increment variable which viewport to use, like this:
    @
    for(viewportIs=1;viewportIs<=2;viewportIs++)
    {

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        switch (viewportIs)
        {
        case 1: glViewport(0,0,this->width()/2,this->height());
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            perspectiveGL(100.0, 0.5*(float)this->width()/this->height(),0.01,1500.0);
            break;
        case 2: glViewport(this->width()/2,0,this->width()/2,this->height());
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            perspectiveGL(100.0, 0.5*(float)this->width()/this->height(),0.01,1500.0);
        default:qDebug() << "default viewport case";
            break;
        }
    

    // draw stuff
    }
    @

    But to no avail. :(

    Edit 2:
    I solved it. Had to put the glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); outside of the for loop, obviously. I thought I had already tried that. Oh well.


Log in to reply
 

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