[Interest] Using OpenGL with Qt

Yves Bailly yves.bailly at sescoi.fr
Mon Mar 17 08:45:54 CET 2014


Greetings all,

I would like to raise again a question which has already been discussed
a bit, without finding a satisfactory answer (for me at least).

It's about using OpenGL, more precisely getting access to OpenGL functions.

Is it possible to use Glew with Qt 5.2? I mean, is it possible to use Glew,
QGLWidget, QOpenGLShader, etc. in the same piece of code?

I know there are the QOpenGLFunctions_* classes, but they're too cumbersome
to use for any heavy work. They somehow require to have a kind of global
instance, e.g.
QOpenGLFunctions_3_3_Core* gl = QOpenGLContext::current()->versionFunctions<...>();
...which then leads to code like
gl->glSomething();
gl->glDoThis();
gl->glDoThat();
...
That "gl->gl" prefix is just odd and makes it almost impossible to reuse
existing, older (Glew-based) code. Just try to copy-paste some GL example
from the web, or copy-paste this "gl->gl" code to some other program not
using Qt. In a even slightly mixed environment, it's really a pain.

And subclassing from QOpenGLFUnctions_* is not an option when you may have
thousands of instances: it's way to much memory and time for each to
resolve its functions.

Note subclassing *can* be an option, if only there was some kind of smart
constructor which would share internals, pretty much like it's done so well
since so long in QString, QImage, containers... Something like this:

class QOpenGLFunctions_3_3_Core
{
   public:
     QOpenGLFunctions_3_3_Core(QOpenGLFunctions_3_3_Core* shared_internals)
     /* ... */
};

Than it can be used easily:

class My_Class: public My_Parent, protected QOpenGLFunctions_3_3_Core
{
   public:
     My_Class(Some_Data data):
       My_Parent(data),
       QOpenGLFunctions_3_3_Core(
         QOpenGLContext::current()
           ->versionFunctions<QOpenGLFunctions_3_3_Core>())
     { }
};

Then from inside "My_Class", no more need for any kind of "gl->" prefix and
everyone is happy :-)

Or maybe I missed something? For now our only alternative is to use Glew,
can you confirm it works well alongside Qt?

Regards,

-- 
      /- Yves Bailly - Software developer   -\
      \- Sescoi R&D  - http://www.sescoi.fr -/
"The possible is done. The impossible is being done. For miracles,
thanks to allow a little delay."



More information about the Interest mailing list