Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple OpenGL Viewports with Qt 5

Tags:

c++

qt

opengl

I would like to render a 3D scene into different viewports. Those viewports are included in "subwindows" with their own menus like this: enter image description here

Each viewport can be:

  • Resized;
  • Hidden;
  • Displayed in full screen;
  • Moved to another part of the application.

So we can have something like: enter image description here

I believe it is better to embed each viewport into a Qt Widget containing my OpenGL widget (is that right?). So how can I render my 3D scene into several Qt OpenGL Widgets?

like image 370
Korchkidu Avatar asked Dec 11 '13 12:12

Korchkidu


1 Answers

I believe it is better to embed each viewport into a Qt Widget containing my OpenGL widget (is that right?).So how can I render my 3D scene into several Qt OpenGL Widgets?

As described in QGlWidget's detailed description, besides overriding initializeGL and paintGL, you also need to override the resizeGL method. In the resizeGL method, you need to adjust the view port, and frustum.

After that, it is just a matter of creating and placing the widgets on the screen. They can be completely independent of each other, and you can set the frustum differently for each.

Since you want to share the opengl context between these widgets, take a look into OpenGL context sharing. To actually do it, you need to pass the OpenGL context object as the first parameter to the constructor of the QGLWidget.

like image 173
BЈовић Avatar answered Sep 30 '22 07:09

BЈовић