QGLFormat Class

The QGLFormat class specifies the display format of an OpenGL rendering context. More...

Header: #include <QGLFormat>
qmake: QT += opengl

This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Public Types

enum OpenGLContextProfile { NoProfile, CoreProfile, CompatibilityProfile }
enum OpenGLVersionFlag { OpenGL_Version_None, OpenGL_Version_1_1, OpenGL_Version_1_2, OpenGL_Version_1_3, OpenGL_Version_1_4, …, OpenGL_ES_Version_2_0 }

Detailed Description

A display format has several characteristics:

  • Double or single buffering.
  • Depth buffer.
  • RGBA or color index mode.
  • Alpha channel.
  • Accumulation buffer.
  • Stencil buffer.
  • Stereo buffers.
  • Direct rendering.
  • Presence of an overlay.
  • Plane of an overlay.
  • Multisample buffers.

You can also specify preferred bit depths for the color buffer, depth buffer, alpha buffer, accumulation buffer and the stencil buffer with the functions: setRedBufferSize(), setGreenBufferSize(), setBlueBufferSize(), setDepthBufferSize(), setAlphaBufferSize(), setAccumBufferSize() and setStencilBufferSize().

Note that even if you specify that you prefer a 32 bit depth buffer (e.g. with setDepthBufferSize(32)), the format that is chosen may not have a 32 bit depth buffer, even if there is a format available with a 32 bit depth buffer. The main reason for this is how the system dependant picking algorithms work on the different platforms, and some format options may have higher precedence than others.

You create and tell a QGLFormat object what rendering options you want from an OpenGL rendering context.

OpenGL drivers or accelerated hardware may or may not support advanced features such as alpha channel or stereographic viewing. If you request some features that the driver/hardware does not provide when you create a QGLWidget, you will get a rendering context with the nearest subset of features.

There are different ways to define the display characteristics of a rendering context. One is to create a QGLFormat and make it the default for the entire application:

 QGLFormat fmt;
 fmt.setAlpha(true);
 fmt.setStereo(true);
 QGLFormat::setDefaultFormat(fmt);

Or you can specify the desired format when creating an object of your QGLWidget subclass:

 QGLFormat fmt;
 fmt.setDoubleBuffer(false);                 // single buffer
 fmt.setDirectRendering(false);              // software rendering
 MyGLWidget* myWidget = new MyGLWidget(fmt, ...);

After the widget has been created, you can find out which of the requested features the system was able to provide:

 QGLFormat fmt;
 fmt.setOverlay(true);
 fmt.setStereo(true);
 MyGLWidget* myWidget = new MyGLWidget(fmt, ...);
 if (!myWidget->format().stereo()) {
     // ok, goggles off
     if (!myWidget->format().hasOverlay()) {
         qFatal("Cool hardware required");
     }
 }

OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other countries.

See also QGLContext and QGLWidget.

Member Type Documentation

enum QGLFormat::OpenGLContextProfile

This enum describes the OpenGL context profiles that can be specified for contexts implementing OpenGL version 3.2 or higher. These profiles are different from OpenGL ES profiles.

ConstantValueDescription
QGLFormat::NoProfile0OpenGL version is lower than 3.2.
QGLFormat::CoreProfile1Functionality deprecated in OpenGL version 3.0 is not available.
QGLFormat::CompatibilityProfile2Functionality from earlier OpenGL versions is available.

This enum was introduced or modified in Qt 4.7.

enum QGLFormat::OpenGLVersionFlag

This enum describes the various OpenGL versions that are recognized by Qt. Use the QGLFormat::openGLVersionFlags() function to identify which versions that are supported at runtime.

ConstantValueDescription
QGLFormat::OpenGL_Version_None0x00000000If no OpenGL is present or if no OpenGL context is current.
QGLFormat::OpenGL_Version_1_10x00000001OpenGL version 1.1 or higher is present.
QGLFormat::OpenGL_Version_1_20x00000002OpenGL version 1.2 or higher is present.
QGLFormat::OpenGL_Version_1_30x00000004OpenGL version 1.3 or higher is present.
QGLFormat::OpenGL_Version_1_40x00000008OpenGL version 1.4 or higher is present.
QGLFormat::OpenGL_Version_1_50x00000010OpenGL version 1.5 or higher is present.
QGLFormat::OpenGL_Version_2_00x00000020OpenGL version 2.0 or higher is present. Note that version 2.0 supports all the functionality of version 1.5.
QGLFormat::OpenGL_Version_2_10x00000040OpenGL version 2.1 or higher is present.
QGLFormat::OpenGL_Version_3_00x00001000OpenGL version 3.0 or higher is present.
QGLFormat::OpenGL_Version_3_10x00002000OpenGL version 3.1 or higher is present. Note that OpenGL version 3.1 or higher does not necessarily support all the features of version 3.0 and lower.
QGLFormat::OpenGL_Version_3_20x00004000OpenGL version 3.2 or higher is present.
QGLFormat::OpenGL_Version_3_30x00008000OpenGL version 3.3 or higher is present.
QGLFormat::OpenGL_Version_4_00x00010000OpenGL version 4.0 or higher is present.
QGLFormat::OpenGL_Version_4_10x00020000OpenGL version 4.1 or higher is present.
QGLFormat::OpenGL_Version_4_20x00040000OpenGL version 4.2 or higher is present.
QGLFormat::OpenGL_Version_4_30x00080000OpenGL version 4.3 or higher is present.
QGLFormat::OpenGL_ES_CommonLite_Version_1_00x00000100OpenGL ES version 1.0 Common Lite or higher is present.
QGLFormat::OpenGL_ES_Common_Version_1_00x00000080OpenGL ES version 1.0 Common or higher is present. The Common profile supports all the features of Common Lite.
QGLFormat::OpenGL_ES_CommonLite_Version_1_10x00000400OpenGL ES version 1.1 Common Lite or higher is present.
QGLFormat::OpenGL_ES_Common_Version_1_10x00000200OpenGL ES version 1.1 Common or higher is present. The Common profile supports all the features of Common Lite.
QGLFormat::OpenGL_ES_Version_2_00x00000800OpenGL ES version 2.0 or higher is present. Note that OpenGL ES version 2.0 does not support all the features of OpenGL ES 1.x. So if OpenGL_ES_Version_2_0 is returned, none of the ES 1.x flags are returned.

See also http://www.opengl.org for more information about the different revisions of OpenGL.

This enum was introduced or modified in Qt 4.2.

See also openGLVersionFlags().