Qt Toolkit - Qt OpenGL 3D Graphics

| Classes - Annotated - Tree - Functions - Home - Structure

# Qt OpenGL 3D Graphics

## Introduction

OpenGL is a standard API for rendering 3D graphics.

OpenGL only deals with 3D rendering and provides little or no support for GUI programming issues. The user interface for an OpenGL application must be created with another toolkit, such as Motif on the X platform, Microsoft Foundation Classes (MFC) under Windows - or Qt on both platforms.

The Qt OpenGL Extension makes it easy to use OpenGL in Qt applications. It provides an OpenGL widget class that can be used just like any other Qt widget, only that it opens an OpenGL display buffer where you can use the OpenGL API to render the contents.

The Qt OpenGL Extension is implemented as a platform-independent Qt/C++ wrapper around the platform-dependent GLX and WGL C APIs. The provided functionality is very similar to Mark Kilgard's GLUT library, but with much more non-OpenGL-specific GUI functionality: the whole Qt API.

## Installation

When you install Qt for X11, you must pass the `-opengl` option to the `configure` script, and you must have OpenGL installed on your system.

When you install Qt for Windows, Qt OpenGL support is included.

The Qt OpenGL modules is not licensed for use with the Qt Professional Edition. Consider upgrading to the Qt Enterprise Edition if you require OpenGL support.

Note about using Mesa on X11: Mesa versions earlier than 3.1 would use the name "MesaGL" and "MesaGLU" for the libraries, instead of "GL" and "GLU". If you want to use a pre-3.1 version of Mesa, you must change the Makefiles to use these library names instead. The easiest way to do this edit the SYSCONF_LIBS_OPENGL line in the config file you are using (qt/configs/*), changing "-lGL -lGLU" to "-lMesaGL -lMesaGLU"; then run "configure" again.

## Building programs

Building your own programs that use the Qt OpenGL Extension is done just like building other Qt programs, the only extra step needed is:

- If you use tmake: Just add the 'qgl' keyword to the 'CONFIG' line.
- Otherwise: Link with the libqgl.a (Unix) or qgl.lib (Windows) library, and add the location of the GL headers to the include path.

See the example programs for details.

## The QGL Classes

The OpenGL support classes in Qt are:

- QGLWidget: An easy-to-use Qt widget for rendering OpenGL scenes.
- QGLContext: Encapsulates an OpenGL rendering context.
- QGLFormat: Specifies the display format of a rendering context.

Many applications need only the high-level QGLWidget class. The other QGL classes provide advanced features.