How to use native OpenGL with Qt 5.4?

I want to use Qt 5.4 to create a window and render with the usual OpenGL functions in this window. In the last few days, I read a lot about Qt classes and how to initialize OpenGL and so on. I think the main classes that I have to deal with are QOpenGLWindow or QOpenGLWidget, but there are QSurface and some other classes. Now I’m very unsure what to do next, and which class I should use to use the simple OpenGL functions, later. Could someone more clearly explain to me what I need to do to configure the Qt GUI in which I can use simple OpenGL?

Some other questions from me:

  • At what point does Qt create a simple OpenGL context? Should I use a QOpenGLContext?
  • What is the difference between QSurface and QOpenGLWindow? The QOpenGLWindow example uses both classes.
  • Can glew be used besides this qt? Here are some questions related to configuring glew with qt, but I think I did not understand why glew is needed.

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

+6
source share
1 answer

At what point does Qt create a simple OpenGL context? Should I use a QOpenGLContext?

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

What is the difference between QSurface and QOpenGLWindow? The QOpenGLWindow example uses both classes.

A QSurface is a base class that represents a "pushed surface" (on or off the screen). QWindow is its on-screen implementation (representing a top-level window), so it inherits from QSurface . You can use QWindow with OpenGL or with a processor-based rasterizer.

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

Can glew be used besides this qt material? Here are some questions related to configuring glew with qt, but I think I did not understand why glew is needed.

Qt is not in your way . And that does not change the use of OpenGL in any way. Just use Qt to create the window and context (in a fully cross-platform way), then you can use GLEW (to resolve OpenGL function pointers, extensions, etc.) or any third-party OpenGL abstraction.

+1
source

Source: https://habr.com/ru/post/990010/


All Articles