Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQGLContext Class Reference
[OpenGL module]

The TQGLContext class encapsulates an OpenGL rendering context. More...

#include <ntqgl.h>

Inherits TQGL.

List of all member functions.

Public Members

Static Public Members

Protected Members


Detailed Description

The TQGLContext class encapsulates an OpenGL rendering context.

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

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 TQGLContext 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 no context current using doneCurrent(). The reset() function will reset the context and make it invalid.

You can examine properties of the context with, e.g. isValid(), isSharing(), initialized(), windowCreated() and overlayTransparentColor().

If you're using double buffering you can swap the screen contents with the off-screen buffer using swapBuffers().

Please note that TQGLContext is not thread safe.

* OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other countries.

See also Graphics Classes and Image Processing Classes.


Member Function Documentation

TQGLContext::TQGLContext ( const TQGLFormat & format, TQPaintDevice * 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 the 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 TQGLContext 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.

See also format() and isValid().

TQGLContext::~TQGLContext () [virtual]

Destroys the OpenGL context and frees its resources.

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

This semi-internal function is called by create(). It creates a system-dependent OpenGL handle that matches the format() of shareContext as closely as possible.

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.

void * TQGLContext::chooseMacVisual ( GDHandle device ) [virtual protected]

Mac only: This virtual function tries to find a visual that matches the format using the given device 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.

See also chooseContext().

int TQGLContext::choosePixelFormat ( void * dummyPfd, HDC pdc ) [virtual protected]

Win32 only This virtual function chooses a pixel format that matches the OpenGL format. Reimplement this function in a subclass if you need a custom context.

Warning: The dummyPfd pointer and pdc are used as a PIXELFORMATDESCRIPTOR*. We use void to avoid using Windows-specific types in our header files.

See also chooseContext().

void * TQGLContext::chooseVisual () [virtual protected]

X11 only: This virtual function tries to find a visual that matches the format, 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 spcific requirements on visual selection.

See also chooseContext().

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

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).

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

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

Warning: Implementation note: initialization of C++ class members usually takes place in the class constructor. TQGLContext 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.

See also chooseContext(), format(), and isValid().

const TQGLContext * TQGLContext::currentContext () [static]

Returns the current context, i.e. the context to which any OpenGL commands will currently be directed. Returns 0 if no context is current.

See also makeCurrent().

TQPaintDevice * TQGLContext::device () const

Returns the paint device set for this context.

See also TQGLContext::TQGLContext().

bool TQGLContext::deviceIsPixmap () const [protected]

Returns TRUE if the paint device of this context is a pixmap; otherwise returns FALSE.

void TQGLContext::doneCurrent () [virtual protected]

Makes no GL context the current context. Normally, you do not need to call this function; TQGLContext calls it as necessary.

TQGLFormat TQGLContext::format () const

Returns the frame buffer format that was obtained (this may be a subset of what was requested).

See also requestedFormat().

void TQGLContext::generateFontDisplayLists ( const TQFont & font, int listBase ) [protected]

Generates a set of 256 display lists for the 256 first characters in the font font. The first list will start at index listBase.

See also TQGLWidget::renderText().

bool TQGLContext::initialized () const [protected]

Returns TRUE if this context has been initialized, i.e. if TQGLWidget::initializeGL() has been performed on it; otherwise returns FALSE.

See also setInitialized().

bool TQGLContext::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.

bool TQGLContext::isValid () const

Returns TRUE if a GL rendering context has been successfully created; otherwise returns FALSE.

void TQGLContext::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.

In some very rare cases the underlying call may fail. If this occurs an error message is output to stderr.

TQColor TQGLContext::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. (Naturally, the color's RGB values are meaningless.)

The returned TQColor object will generally work as expected only when passed as the argument to TQGLWidget::qglColor() or TQGLWidget::qglClearColor(). Under certain circumstances it can also be used to draw transparent graphics with a TQPainter. See the examples/opengl/overlay_x11 example for details.

TQGLFormat TQGLContext::requestedFormat () const

Returns the frame buffer format that was originally requested in the constructor or setFormat().

See also format().

void TQGLContext::reset () [virtual]

Resets the context and makes it invalid.

See also create() and isValid().

void TQGLContext::setFormat ( const TQGLFormat & 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.

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

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

void TQGLContext::setInitialized ( bool on ) [protected]

If on is TRUE the context has been initialized, i.e. TQGLContext::setInitialized() has been called on it. If on is FALSE the context has not been initialized.

See also initialized().

void TQGLContext::setWindowCreated ( bool on ) [protected]

If on is TRUE the context has had a window created for it. If on is FALSE no window has been created for the context.

See also windowCreated().

void TQGLContext::swapBuffers () const [virtual]

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

See also TQGLFormat::setDoubleBuffer().

bool TQGLContext::windowCreated () const [protected]

Returns TRUE if a window has been created for this context; otherwise returns FALSE.

See also setWindowCreated().


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8