QSurfaceFormat Vs. QGLFormat [resolved]

  • I see two different OpenGL setup examples and one uses QGLFormat and the QSurfaceFormat. the two classes seem similar. Could someone clarify why these classes seem to be doing similar functions.

    My need is. I have a editor window I want to put a QGLWidget into. There are no two examples that show the same way to set up a openGL window in Qt. Could someone give me some guidance?

  • There are different ways to work with OpenGL in Qt. The older one, coming from Qt4 was to use QGLWidget, that in turn uses QGLFormat to set up OpenGL parameters.

    Moving on to Qt5 widgets and windows have been separated and now we can have a QWindow that is not a widget (eg. for QtQuick or native stuff). This QWindow uses QSurface as a rendering surface and it can use OpenGL or other painting mechanisms. The QSurfaceFormat describes that format, and in particular various options of the OpenGL context creation.

    So if you're using widgets you can go with QGLFormat else use the newer classes.

  • Moderators


    [quote author="chrisaverage" date="1410007598"]So if you're using widgets you can go with QGLFormat else use the newer classes.[/quote]Bear in mind that in Qt 5.4, which is scheduled to be released at the "end of October 2014":http://qt-project.org/wiki/Qt-5.4-release, will introduce the new "QOpenGLWidget":http://doc-snapshot.qt-project.org/qt5-5.4/qopenglwidget.html class.

    QOpenGLWidget is designed to replace QGLWidget and it will use QSurfaceFormat. As of Qt 5.4, all classes that are prefixed with "QGL" (including QGLFormat) will be fully deprecated, and their usage will be discouraged.

    I'd suggest starting with QGLWidget + QGLFormat for now, and consider changing over to QOpenGLWidget + QSurfaceFormat when Qt 5.4 arrives (if you upgrade to Qt 5.4, that is)

  • Thank you. These answers are very insightful

Log in to reply