|  | Home · Overviews · Examples

# QGLFormat Class Reference
[com.trolltech.qt.opengl module]

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

## Detailed Description

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

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.
- The plane of an overlay format.
- Multisample buffers.

You can also specify preferred bit depths for the depth buffer, alpha buffer, accumulation buffer and the stencil buffer with the functions: `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`.