Search code examples
openglqt5qwidget

creating several OpenGL widgets in QMainWindow


I work with Qt5 and must code something like simple 3D-editor. I need to have 4 projection-views in my main window (for different scene-projections). I saw OpenGLWindow example, but there was only one window and i don't know how to modify it for my purpose.

There are next lines in example.

class OpenGLWindow : public QWindow, protected QOpenGLFunctions { ........ private: QOpenGLContext *m_context; }

As Assistant says, QOpenGLContext can draw only on QSufrace, which is direct base of QWindow.

So, how can I put several projection-views on one MainWindow.

I need tools, contained in QOpenGLFunctions.


Solution

  • You only need to have one QOpenGLContext. Drawing multiple views is usually done by like this:

    //Top Left
    glViewport (0, windowHeight/2, windowWidth/2, windowHeight/2);
    draw();
    
    //Top Right
    glViewport (windowWidth/2, windowHeight/2, windowWidth/2, windowHeight/2);
    draw();
    
    //Bottom Right
    glViewport (windowWidth/2, 0, windowWidth/2, windowHeight/2); 
    draw();
    
    //Bottom Left
    glViewport (0, 0, windowWidth/2, windowHeight/2);
    draw();