The QGLContext class encapsulates an OpenGL rendering context.
.PP
An OpenGL<sup>*</sup> rendering context is a complete set of OpenGL state variables.
.PP
The context's format is set in the constructor or later with setFormat(). The format options that are actually set are returned by format(); the options you asked for are returned by requestedFormat(). Note that after a QGLContext object has been constructed, the actual OpenGL context must be created by explicitly calling the create() function. The makeCurrent() function makes this context the current rendering context. You can make \fIno\fR context current using doneCurrent(). The reset() function will reset the context and make it invalid.
.PP
You can examine properties of the context with, e.g. isValid(), isSharing(), initialized(), windowCreated() and overlayTransparentColor().
.PP
If you're using double buffering you can swap the screen contents with the off-screen buffer using swapBuffers().
.PP
Please note that QGLContext is not thread safe.
.PP
<sup>*</sup> OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other countries.
.PP
See also Graphics Classes and Image Processing Classes.
Constructs an OpenGL context for the paint device \fIdevice\fR, which can be a widget or a pixmap. The \fIformat\fR specifies several display options for the context.
.PP
If the underlying OpenGL/Window system cannot satisfy all the features requested in \fIformat\fR, the nearest subset of features will be used. After creation, the format() method will return the actual format obtained.
.PP
Note that after a QGLContext object has been constructed, create() must 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.
.PP
See also format() and isValid().
.SH "QGLContext::~QGLContext ()\fC [virtual]\fR"
Destroys the OpenGL context and frees its resources.
This semi-internal function is called by create(). It creates a system-dependent OpenGL handle that matches the format() of \fIshareContext\fR as closely as possible.
.PP
On Windows, it calls the virtual function choosePixelFormat(), which finds a matching pixel format identifier. On X11, it calls the virtual function chooseVisual() which finds an appropriate X visual. On other platforms it may work differently.
\fBMac only\fR: This virtual function tries to find a visual that matches the format using the given \fIdevice\fR handle, reducing the demands if the original request cannot be met.
The algorithm for reducing the demands of the format is quite simple-minded, so override this method in your subclass if your application has specific requirements on visual selection.
\fBWin32 only\fR This virtual function chooses a pixel format that matches the OpenGL format. Reimplement this function in a subclass if you need a custom context.
.PP
\fBWarning:\fR The \fIdummyPfd\fR pointer and \fIpdc\fR are used as a \fCPIXELFORMATDESCRIPTOR*\fR. We use \fCvoid\fR to avoid using Windows-specific types in our header files.
The algorithm for reducing the demands of the format is quite simple-minded, so override this method in your subclass if your application has spcific requirements on visual selection.
Creates the GL context. Returns TRUE if it was successful in creating a valid GL rendering context on the paint device specified in the constructor; otherwise returns FALSE (i.e. the context is invalid).
.PP
After successful creation, format() returns the set of features of the created GL rendering context.
.PP
If \fIshareContext\fR points to a valid QGLContext, this method will try to establish OpenGL display list sharing between this context and the \fIshareContext\fR. Note that this may fail if the two contexts have different formats. Use isSharing() to see if sharing succeeded.
.PP
\fBWarning:\fR 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 problem is that virtual functions are not properly called during construction (even though this is correct C++) because C++ constructs class hierarchies from the bottom up. For this reason we need a create() function.
.PP
See also chooseContext(), format(), and isValid().
Returns TRUE if this context has been initialized, i.e. if QGLWidget::initializeGL() has been performed on it; otherwise returns FALSE.
.PP
See also setInitialized().
.SH "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; otherwise returns FALSE. Note that display list sharing might not be supported between contexts with different formats.
.SH "bool QGLContext::isValid () const"
Returns TRUE if a GL rendering context has been successfully created; otherwise returns FALSE.
If this context is a valid context in an overlay plane, returns the plane's transparent color. Otherwise returns an invalid color.
.PP
The returned color's pixel value is the index of the transparent color in the colormap of the overlay plane. (Naturally, the color's RGB values are meaningless.)
The returned TQColor object will generally work as expected only 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 examples/opengl/overlay_x11 example for details.
Returns the frame buffer format that was originally requested in the constructor or setFormat().
.PP
See also format().
.SH "void QGLContext::reset ()\fC [virtual]\fR"
Resets the context and makes it invalid.
.PP
See also create() and isValid().
.SH "void QGLContext::setFormat ( const QGLFormat & format )\fC [virtual]\fR"
Sets a \fIformat\fR for this context. The context is reset.
.PP
Call create() to create a new GL context that tries to match the new format.
.PP
.nf
.br
QGLContext *cx;
.br
// ...
.br
QGLFormat f;
.br
f.setStereo( TRUE );
.br
cx->setFormat( f );
.br
if ( !cx->create() )
.br
exit(); // no OpenGL support, or cannot render on the specified paintdevice
.br
if ( !cx->format().stereo() )
.br
exit(); // could not create stereo context
.br
.fi
.PP
See also format(), reset(), and create().
.SH "void QGLContext::setInitialized ( bool on )\fC [protected]\fR"
If \fIon\fR is TRUE the context has been initialized, i.e. QGLContext::setInitialized() has been called on it. If \fIon\fR is FALSE the context has not been initialized.
.PP
See also initialized().
.SH "void QGLContext::setWindowCreated ( bool on )\fC [protected]\fR"
If \fIon\fR is TRUE the context has had a window created for it. If \fIon\fR is FALSE no window has been created for the context.