Qt logo

QGLContext Class Reference


The QGLContext class encapsulates an OpenGL rendering context. This class is part of the Qt OpenGL Extension. More...

#include <qgl.h>

List of all member functions.

Public Members

Protected Members


Detailed Description

This class is defined in the Qt OpenGL Extension, which can be found in the qt/extensions directory. It is not included in the main Qt API.

The QGLContext class encapsulates an OpenGL rendering context.

An OpenGL rendering context is a complete set of OpenGL state variables.


Member Function Documentation

QGLContext::QGLContext ( const QGLFormat & format, QPaintDevice * device )

Constructs an OpenGL context for the paint device device, which must be a widget or a pixmap. The format specifies several display options for this context.

The context will be invalid if the format settings cannot be satified by the underlying OpenGL/Window system.

See also: isValid().

QGLContext::~QGLContext () [virtual]

Destroys the OpenGL context.

bool QGLContext::chooseContext ( const QGLContext * shareContext = 0 = 0 ) [virtual protected]

This semi-internal function is called by create(). It creates a system-dependent OpenGL handle that matches the specified format.

Windows: Calls choosePixelFormat() which finds a matching pixel format identifier.

X11: Calls chooseVisual() which finds an appropriate X visual.

choosePixelFormat() and chooseVisual() can be reimplemented in a subclass if you need to choose a very custom context.

bool QGLContext::create ( const QGLContext * shareContext = 0 ) [virtual]

Creates the GL context. Returns TRUE if it was successful in creating a context that satisfies the requested format, otherwise FALSE is returned (the context is invalid).

If successful and the shareContext points to a valid QGLContext, this context will share OpenGL display lists with shareContext.

Implementation note: Initialization of C++ class members usually takes place in the class constructor. QGLContext is an exception because it must be simple to customize. The virtual functions chooseContext() (and chooseVisual() for X11) can be reimplemented in a subclass to select a particular context. The trouble is that virtual functions are not properly called during construction (which is indeed correct C++), hence we need a create() function.

See also: chooseContext() and isValid().

QPaintDeviceQGLContext::device () const

Returns the paint device set for this context.

See also: QGLContext::QGLContext().

void QGLContext::doneCurrent () [virtual protected]

Resets the current OpenGL rendering context. Normally, you do not need to call this function, because makeCurrent() takes care of that.

const QGLFormatQGLContext::format () const

Returns the format.

See also: setFormat().

bool QGLContext::isValid () const

Returns TRUE if the characteristics specified in the display format could be fulfilled by the OpenGL driver/window system.

void QGLContext::makeCurrent () [virtual]

Makes this context the current OpenGL rendering context. All gl functions you call operate on this context until another context is made current.

void QGLContext::reset () [virtual]

Resets the context and makes it invalid.

See also: create() and isValid().

void QGLContext::setFormat ( const QGLFormat & format ) [virtual]

Sets a new OpenGL context specification format. The context is reset. Call create() to create a new context that matches this format.

    QGLContext *cx;
      ...
    QGLFormat f;
    f.setAlpha( TRUE );
    f.setStereo( TRUE );
    cx->setFormat( f );
    if ( !cx->create() )
        ; // could not create context

See also: format(), reset() and create().

void QGLContext::swapBuffers () [virtual]

Swaps the screen contents with an off-screen buffer. Works only if the context is in double buffer mode.

See also: QGLFormat::setDoubleBuffer().


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-98 Troll Tech, all rights reserved.

It was generated from the following files:


Copyright © 1998 Troll TechTrademarks
Qt version 1.42