6

I want to use Qt 5.4 to create a window and render with normal OpenGL functions some stuff in that window. In the last few days, I read a lot about the Qt classes and how to initialize OpenGL and so on. I think, the main classes I have to deal with are QOpenGLWindow or QOpenGLWidget, but there are the QSurface and some other classes too. Now I am very unsure about what doing next and which class I should use to use the plain OpenGL functions, later. Can someone explain more clearly to me what I have to do to set up a Qt GUI in which I can use plain OpenGL?

Some other questions from me are:

  • At which point does Qt create a plain OpenGL context? Do I have to use the QOpenGLContext?
  • What is exactly the difference between a QSurface and a QOpenGLWindow? In the QOpenGLWindow example both classes are used.
  • Is it possible to use glew besides this qt stuff? Here are some question on, which deal with setting up glew with qt, but I think that I did not get the real point of why glew is needed.

Edit: I discussed this question with a colleague and our only conclusion was to use Offscreen-Rendering. Does anyone know another solution?

DanceIgel
  • 714
  • 8
  • 25
  • Have you looked at the [OpenGL Window Exemple](http://doc.qt.io/qt-5/qtgui-openglwindow-example.html) (although it doesn't use the `QOpenGLWindow` class) ? [`QSurface`](http://doc.qt.io/qt-5/qsurface.html) is a pure virtual base class of `QWindow` and so of `QOpenGLWindow` too. Apparently `QOpenGLWindow` works like `QOpenGLWidget` and `QOpenGLWidget` [has more complete documentation](http://doc.qt.io/qt-5/qopenglwidget.html#details). – Leiaz Jun 30 '15 at 18:15
  • There's also a QOpenGLWindow example shipped with Qt. – peppe Jun 30 '15 at 19:07

1 Answers1

2

At which point does Qt create a plain OpenGL context? Do I have to use the QOpenGLContext?

Either where it's documented (for instance, creating a QOpenGLWidget or a QOpenGLWindow will automatically create a context), or you can create a context manually at any time by creating a QOpenGLContext object.

What is exactly the difference between a QSurface and a QOpenGLWindow? In the QOpenGLWindow example both classes are used.

A QSurface is a base class representing a "drawable surface" (onscreen or offscreen). QWindow is its onscreen implementation (representing a top level window), so it inherits from QSurface. You can draw over a QWindow by using OpenGL or by using a CPU-based rasterizer.

Finally, QOpenGLWindow is a QWindow subclass which offers some extra functionality and convenience, by automatically creating and managing an OpenGL context (via QOpenGLContext), having an optional partial-update strategy (through the usage of a FBO), etc.

Is it possible to use glew besides this qt stuff? Here are some question on, which deal with setting up glew with qt, but I think that I did not get the real point of why glew is needed.

Qt is not in your way. And it doesn't change your usage of OpenGL in any way. Just use Qt to create a window and a context (in a totally cross platform way), then you're free to use GLEW (to resolve OpenGL function pointers, extensions, etc.) or any 3rd party OpenGL abstraction.

peppe
  • 21,934
  • 4
  • 55
  • 70
  • except that QT IS IN MY WAY because I cannot make my manually created OpenGLContext current on any QWidgets, only QSurfaces, if I want a current OpenGLContext in a QWIdget, I have to resolve to only use the QT managed context that is guaranteed to be current in initializeGL(), paintGL(), and resizeGL() – ComradeJoecool Nov 01 '17 at 16:13
  • A QWidget is not a OpenGL surface, so "making a context current on it" doesn't make sense. You need a real surface to do what you want -- e.g. by using a plain QWindow and wrapping it in a widget via `QWidget::createWindowContainer`. That's not "being in your way", that's playing by the rules of the game (which by the way are dictated by OpenGL, not Qt). – peppe Nov 01 '17 at 22:40
  • ok, so I should have mentioned that it is not QWidget, but rather QOpenGlWidget, I can use OpenGL on it, but only if I do it QT's way, that IS "in my way" – ComradeJoecool Nov 07 '17 at 17:34
  • Because QOpenGLWidget is not a window surface. As I said, if you want the "fully native" way, you can: QWindow + QOpenGLContext + QWidget::createWindowSurface. QOpenGLWidget is a different kind of solution, with some pros and cons. – peppe Nov 07 '17 at 20:15
  • by the way, QGestures are not supported on QWindows and jamming a QWindow into a QWidget with QWidget::createWindowContainer() has its own set of limitations and known issues – ComradeJoecool Nov 08 '17 at 23:43
  • I'd like to be constructive -- could you please post a question with the problems you're facing with QOpenGLWidget, maybe there's some acceptable solution for you, I'd love to help if possible. – peppe Nov 09 '17 at 23:45
  • it's been asked https://stackoverflow.com/questions/47058621/qopenglwidget-with-qapplication – ComradeJoecool Nov 10 '17 at 15:21