[Interest] QGLWidget and OGL version 4.3 functions?

Sean Harmer sh at theharmers.co.uk
Sun Sep 29 11:21:41 CEST 2013


Hi,

On 27/09/2013 07:35, Thomas Meyer wrote:
> Hi,
> is it possible to render in a QGLWidget with the OGL 4.3 functions?

Yes but it is now recommended to use QWindow + QOpenGLContext for new 
code as QGLWidget will not see any further development.

> If so, how can I call the functions?

You need to get hold of the function entry points for the OpenGL 4.3 
functions. This can be done via the QOpenGLContext to get a pointer to a 
QOpenGLFunctions_4_3_Core or QOpenGLFunctions_4_3_Compatibility object 
depending upon which profile you are using.

If using a QOpenGLContext directly you can just do something like this:

QSurfaceFormat f;
f.setVersion(4, 3);
f.setProfile(QSurfaceFormat::CoreProfile);

m_context = new QOpenGLContext( this );
m_context->setFormat( f );
m_context->create();

QOpenGLFunctions_4_3_Core *funcs = 
m_context->versionFunctions<QOpenGLFunctions_4_3_Core>();
if (!funcs) {
     qDebug() << "Could not obtain OpenGL 4.3 function entry points";
     return;
}
funcs->initializeOpenGLFunctions();

// From here you can use funcs to call any OpenGL 4.3 function
funcs->glTextureView(...);

If you are using QGLWidget then instead of creating your own context as 
in the above code you can get hold of QGLWidget's context via:

QOpenGLContext *context = m_glWidget->context()->contextHandle();

then follow the above to get the QOpenGLFunctions_4_3_Core pointer. Just 
remember to ask QGLWidget to create a 4.3 context via QGLFormat 
(analogous to QSurfaceFormat above).

Hope this helps,

Sean




More information about the Interest mailing list