0

Goal:

In my application I'm trying to implement multiple viewports to allow the user to view a scene from multiple perspectives. Each of my viewports need to be able to switch between wireframe, shaded, lighting, etc. I can currently render from different perspectives in each viewport, but I have issues.

Problem:

When I try to set various settings such as glPolygonMode() or qglClearColor() within any viewport, these settings only seem to apply to a single viewport, generally the very last viewport that was created. This isn't a signals/slots issue, since these connections are handled internally within each widget, and cannot be mixed up between widgets.

Attempts at solving the problem:

Since I'm using Qt as the library for managing all UI related things, I'm sure there are a lot of things Qt has taken care of for creating and setting up each OpenGL instance for me, so there may be things that I'm overlooking that I don't know about.

I've checked the constructors available for QGLWidgets, and seen that a QGLWidget can take in another QGLWidget as a "sharedwidget", and also a QGLContext object.

  • I currently use the "sharedwidget" route, because without it for some reason I can't get textures to bind for more than 1 viewport. However, this doesn't solve the problem of not being able to switch between wireframe or shaded in each QGLWidget instance.
  • I've also tried the QGLContext route. By default each QGLWidget creates a new context anyways, but when trying to assign new ones or sharing a single Context between all of them I would just get issues with my shaders not linking (I believe the initializeGL slot is not getting called in that case), leading to a crash every time a context is shared to another QGLWidget:

ASSERT: "QOpenGLFunctions::isInitialized(d_ptr)" in file c:\work\build\qt5_workdir\w\s\qtbase\include\qtgui../../src/gui/opengl/qopenglfunctions.h, line 2018

Details:

Currently, my application takes on the following hierarchy:

  • Application
    • Window
      • ViewportWidget [dynamic array]
        • QGLWidget (custom variation)

The only thing each QGLWidget needs to share is the pointer to the current "map", so that each can render the map based on whatever settings are set within that particular widget's instance.

I perform the following functions for setting up a viewport:

  • I create a new ViewportWidget, parent it and add it to the appropriate frame and Layout. If the viewport isn't the first one, then it also passes the very first QGLWidget to be used as a "sharedwidget"
  • The viewport then creates a QGLFormat with a swap interval of 1, and passes said format into the constructor of a new QGLWidget.
  • I then am forced to call "makeCurrent()" for the viewport, otherwise I crash with the reason:

ASSERT: "false" in file qgl.cpp, line 122

Is it even possible to have separate QGLWidgets with different "polygonMode"'s, or "clearColor"'s? I'm just worried that I'm doing something wrong that will bite me in the butt later on, which I want to avoid.

Yattabyte
  • 1,280
  • 14
  • 28
  • 1
    Not sure how QGLWidget works, but it they create different OpenGL contexts, then you will need to make the context of the one you're currently drawing to current to actually use it. – Colonel Thirty Two Apr 28 '15 at 19:20
  • Maybe you should use one single QTglwidget and split it with glViewport and 4 projections Mat's or use 4 frame buffers, decreasing cycle for other views that the one active... – j-p Apr 29 '15 at 09:28

0 Answers0