[Interest] OpenGL and resolving gl functions

Sletta Gunnar Gunnar.Sletta at digia.com
Tue Dec 3 09:01:31 CET 2013

1: The QOpenGLWidget is still planned, but we didn't have time to do in for 5.2, so it has been delayed for a later release.

2: When you have Qt-only GL code, you get the benefit of Qt resolving OpenGL functions for you as you have already noticed. You can either subclass the QOpenGLFunctions to avoid prefixing each GL call with the functions object or pass the QOpenGLFunctiion object around or grab it in any arbitrary function using QOpenGLContext::currentContext()->functions(). Similar with the versioned functions classes for later OpenGL desktop versions.

When you mix Qt OpenGL with other code that does not know about Qt's OpenGL functions it will normally resolve the functions it needs itself, for instance using GLEW or just manually resolving what it needs. This generally works just fine, but the trick to keep in mind is to make sure that Qt and that library uses the same OpenGL. For instance, an ANGLE build on windows will use ANGLE's OpenGL and not the built-in opengl.dll on windows. Similarily, if you configure Qt on linux to use EGL rather than XGL, you will also have to make sure that the other library does the same.


Fra: interest-bounces+gunnar.sletta=digia.com at qt-project.org [interest-bounces+gunnar.sletta=digia.com at qt-project.org] på vegne av Roger Leigh [rleigh at codelibre.net]
Sendt: 2. desember 2013 17:56
To: interest at qt-project.org
Emne: [Interest] OpenGL and resolving gl functions


I'm fairly new to using OpenGL with Qt, so apologies if these
questions are too basic.

I've created some fairly simple programs with QGLWidget and
lately converted these to use a reparented QWindow +
QOpenGLFunctions using QWidget::createWindowContainer which
works OK.  These were all based upon what the Qt OpenGL
examples and documention were recommending.

1) I read that there were plans to create a QOpenGLWidget
   class to replace QGLWidget in 5.2.0, and I found
   QTBUG-31771, but this has very little information.  Is this
   still planned?  It would certainly make things a bit simpler!

2) This is a bit more general, and relates to how to best use
   the GL API with Qt.

   When using a class inheriting QOpenGLFunctions I get the GL
   functions made available, and if I copy the Qt OpenGL
   examples and do all my drawing in a paintGL/render (or
   equivalent) method then this is fine--the functions are all
   exposed in the class method.

   However, I'm wondering what to do when things become more
   complex, and I have (for example) many hundreds of objects
   of which is responsible for drawing itself, or if I have a
   number of helper classes which might be using plain OpenGL
   and be unaware of Qt.  How best to structure things so that
   I can have more complex drawing and computation kept
   separate from the Qt OpenGL view(s)?  What sorts of strategies
   should be employed to get the OpenGL functions made available
   to these classes?  Deriving each from QOpenGLFunctions seems a
   little excessive (and might not even be possible).  But using
   some additional facility like GLEW also seems impractical given
   its incompatibility with QOpenGLFunctions and also seems

I'd be very interested in any insights anyone can share.

Many thanks,

  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux    http://people.debian.org/~rleigh/
 `. `'   schroot and sbuild  http://alioth.debian.org/projects/buildd-tools
   `-    GPG Public Key      F33D 281D 470A B443 6756 147C 07B3 C8BC 4083 E800
Interest mailing list
Interest at qt-project.org

More information about the Interest mailing list