QGLContext(3qt)

NAME
QGLContext - Encapsulates an OpenGL rendering context

#include <qgl.h>

Inherits QGL.

  Public Members
QGLContext ( const QGLFormat & format, QPaintDevice * device )
virtual ~QGLContext ()
virtual bool create ( const QGLContext * shareContext = 0 )
bool isValid () const
bool isSharing () const
virtual void reset ()
QGLFormat format () const
virtual void setFormat ( const QGLFormat & format )
virtual void makeCurrent ()
virtual void swapBuffers () const
QPaintDevice* device () const
QColor overlayTransparentColor () const

  Static Public Members
const QGLContext* currentContext ()

  Protected Members
virtual bool chooseContext ( const QGLContext * shareContext = 0 )
virtual void doneCurrent ()
bool deviceIsPixmap () const
bool windowCreated () const
void setWindowCreated ( bool on )
bool initialized () const
void setInitialized ( bool on )
uint colorIndex ( const QColor & c ) const (internal)

DESCRIPTION
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 can be a widget or a pixmap. The format specifies several display options for this context.

If the underlying OpenGL/Window system cannot satisfy all the features requested in format, the nearest subset of features will be used. After creation, the format() method will return the actual format obtained.

Note that after a QGLContext object have been constructed, create() have to be called explicitly to create the actual OpenGL context. The context will be invalid if it was not possible to obtain a GL context at all.

See also format() and 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 as closely as possible.

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 GL rendering context on the paint device specified in the constructor, otherwise FALSE is returned (the context is invalid).

After successful creation, format() returns the set of features of the created GL rendering context.

If shareContext points to a valid QGLContext, this method will try to establish OpenGL display list sharing between this context and shareContext. Note that this may fail if the two contexts have different formats. Use isSharing() to test.

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(), format() and isValid().

const QGLContext* QGLContext::currentContext () [static]
Returns the current context, i.e. the context to which any OpenGL commands will currently be directed to. Returns 0 if no context is current.

See also makeCurrent().

QPaintDevice* QGLContext::device () const
Returns the paint device set for this context.

See also QGLContext::QGLContext().

bool QGLContext::deviceIsPixmap () const [protected]
Returns TRUE if the paint device of this context is a pixmap, otherwise FALSE.

void QGLContext::doneCurrent () [virtual protected]
Makes no GL context the current context. Normally, you do not need to call this function, QGLContext calls it as necessary.

QGLFormat QGLContext::format () const
Returns the format.

bool QGLContext::initialized () const [protected]
Returns TRUE if this context has been initialized, i.e. if QGLWidget::initializeGL() has been performed on it.

See also setInitialized().

bool QGLContext::isSharing () const
Returns TRUE if display list sharing with another context was requested in the create() call, and the GL system was able to fulfill this request. Note that display list sharing may possibly not be supported between contexts with different formats.

bool QGLContext::isValid () const
Returns TRUE if a GL rendering context has been successfully created.

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.

QColor QGLContext::overlayTransparentColor () const
If this context is a valid context in an overlay plane, returns the plane's transparent color. Otherwise returns an invalid color.

The returned color's pixel value is the index of the transparent color in the colormap of the overlay plane. The color's RGB values are meaningless, of course.

The returned QColor object will generally only work as expected when passed as the argument to QGLWidget::qglColor() or QGLWidget::qglClearColor(). Under certain circumstances it can also be used to draw transparent graphics with a QPainter; see the" overlay_x11" example for details.

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 format for this context. The context is reset.

Call create() to create a new GL context that tries to match the new format.

    QGLContext *cx;
      ...
    QGLFormat f;
    f.setStereo( TRUE );
    cx->setFormat( f );
    if ( !cx->create() )
        exit(); // no OpenGL support, or cannot render on specified paintdevice
    if ( !cx->format().stereo() )
        exit(); // could not create stereo context

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

void QGLContext::setInitialized ( bool on ) [protected]
Tells the context whether it has been initialized, i.e. whether QGLWidget::initializeGL() has been performed on it.

See also initialized().

void QGLContext::setWindowCreated ( bool on ) [protected]
Tells the context whether a window has already been created for it.

See also windowCreated().

void QGLContext::swapBuffers () const [virtual]
Swaps the screen contents with an off-screen buffer. Works only if the context is in double buffer mode.

See also QGLFormat::setDoubleBuffer().

bool QGLContext::windowCreated () const [protected]
Returns TRUE if a window has been created for this context, otherwise FALSE.

See also setWindowCreated().

uint QGLContext::colorIndex ( const QColor & c ) const [protected]
For internal use only.

SEE ALSO
http://doc.trolltech.com/qglcontext.html http://www.trolltech.com/faq/tech.html

COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.

AUTHOR
Generated automatically from the source code.

BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports make our job much simpler. Thank you.

In case of content or formattting problems with this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qglcontext.3qt) and the Qt version (2.3.5).