Qt Jambi Home

com.trolltech.qt.opengl
Class QGLWidget

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QWidget
                  extended by com.trolltech.qt.opengl.QGLWidget
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface

public class QGLWidget
extends QWidget

The QGLWidget class is a widget for rendering OpenGL graphics.

QGLWidget provides functionality for displaying OpenGL graphics integrated into a Qt application. It is very simple to use. You inherit from it and use the subclass like any other QWidget, except that you have the choice between using QPainter and standard OpenGL rendering commands.

QGLWidget provides three convenient virtual functions that you can reimplement in your subclass to perform the typical OpenGL tasks:

Here is a rough outline of how a QGLWidget subclass might look:

    class MyGLDrawer : public QGLWidget
    {
        Q_OBJECT        // must include this if you use Qt signals/slots

    public:
        MyGLDrawer(QWidget *parent)
            : QGLWidget(parent) {}

    protected:

        void initializeGL()
        {
            // Set up the rendering context, define display lists etc.:
            ...
            glClearColor(0.0, 0.0, 0.0, 0.0);
            glEnable(GL_DEPTH_TEST);
            ...
        }

        void resizeGL(int w, int h)
        {
            // setup viewport, projection etc.:
            glViewport(0, 0, (GLint)w, (GLint)h);
            ...
            glFrustum(...);
            ...
        }

        void paintGL()
        {
            // draw the scene:
            ...
            glRotatef(...);
            glMaterialfv(...);
            glBegin(GL_QUADS);
            glVertex3f(...);
            glVertex3f(...);
            ...
            glEnd();
            ...
        }

    };

If you need to trigger a repaint from places other than paintGL (a typical example is when using timers to animate scenes), you should call the widget's updateGL function.

Your widget's OpenGL rendering context is made current when paintGL, resizeGL, or initializeGL is called. If you need to call the standard OpenGL API functions from other places (e.g. in your widget's constructor or in your own paint functions), you must call makeCurrent first.

QGLWidget provides functions for requesting a new display format and you can also create widgets with customized rendering contexts.

You can also share OpenGL display lists between QGLWidgets (see the documentation of the QGLWidget constructors for details).

Overlays

The QGLWidget creates a GL overlay context in addition to the normal context if overlays are supported by the underlying system.

If you want to use overlays, you specify it in the format. (Note: Overlay must be requested in the format passed to the QGLWidget constructor.) Your GL widget should also implement some or all of these virtual methods:

These methods work in the same way as the normal paintGL etc. functions, except that they will be called when the overlay context is made current. You can explicitly make the overlay context current by using makeOverlayCurrent, and you can access the overlay context directly (e.g. to ask for its transparent color) by calling overlayContext.

On X servers in which the default visual is in an overlay plane, non-GL Qt windows can also be used for overlays.

Painting Techniques

As described above, subclass QGLWidget to render pure 3D content in the following way:

It is also possible to draw 2D graphics onto a QGLWidget subclass, it is necessary to reimplement QGLWidget::paintEvent() and do the following:

Overpainting 2D content on top of 3D content takes a little more effort. One approach to doing this is shown in the Overpainting example.

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

See Also:
QGLPixelBuffer, GL Example, Painting Example, Example, Example

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget
QWidget.RenderFlag, QWidget.RenderFlags
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 
Fields inherited from class com.trolltech.qt.gui.QWidget
customContextMenuRequested
 
Constructor Summary
QGLWidget()
          Equivalent to QGLWidget(0, 0, 0).
QGLWidget(QGLContext context)
          Equivalent to QGLWidget(context, 0, 0, 0).
QGLWidget(QGLContext context, QWidget parent)
          Equivalent to QGLWidget(context, parent, 0, 0).
QGLWidget(QGLContext context, QWidget parent, QGLWidget shareWidget)
          Equivalent to QGLWidget(context, parent, shareWidget, 0).
QGLWidget(QGLContext context, QWidget parent, QGLWidget shareWidget, Qt.WindowFlags f)
          Constructs an OpenGL widget with parent parent.
QGLWidget(QGLFormat format)
          Equivalent to QGLWidget(format, 0, 0, 0).
QGLWidget(QGLFormat format, QWidget parent)
          Equivalent to QGLWidget(format, parent, 0, 0).
QGLWidget(QGLFormat format, QWidget parent, QGLWidget shareWidget)
          Equivalent to QGLWidget(format, parent, shareWidget, 0).
QGLWidget(QGLFormat format, QWidget parent, QGLWidget shareWidget, Qt.WindowFlags f)
          Constructs an OpenGL widget with parent parent.
QGLWidget(QWidget parent)
          Equivalent to QGLWidget(parent, 0, 0).
QGLWidget(QWidget parent, QGLWidget shareWidget)
          Equivalent to QGLWidget(parent, shareWidget, 0).
QGLWidget(QWidget parent, QGLWidget shareWidget, Qt.WindowFlags f)
          Constructs an OpenGL widget with a parent widget.
 
Method Summary
protected  boolean autoBufferSwap()
          Returns true if the widget is doing automatic GL buffer swapping; otherwise returns false.
 int bindTexture(QImage image)
          Equivalent to bindTexture(image, GL_TEXTURE_2D, GL_RGBA).
 int bindTexture(QImage image, int target)
          Equivalent to bindTexture(image, target, GL_RGBA).
 int bindTexture(QImage image, int target, int format)
          Calls QGLContext:::bindTexture(image, target, format) on the currently set context.
 int bindTexture(QPixmap pixmap)
          Equivalent to bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA).
 int bindTexture(QPixmap pixmap, int target)
          Equivalent to bindTexture(pixmap, target, GL_RGBA).
 int bindTexture(QPixmap pixmap, int target, int format)
          Calls QGLContext:::bindTexture(pixmap, target, format) on the currently set context.
 int bindTexture(java.lang.String fileName)
          Calls QGLContext::bindTexture(fileName) on the currently set context.
 QGLColormap colormap()
          Returns the colormap for this widget.
 QGLContext context()
          Returns the context of this widget.
static QImage convertToGLFormat(QImage img)
          Converts the image img into the unnamed format expected by OpenGL functions such as glTexImage2D().
 void deleteTexture(int tx_id)
          Calls QGLContext::deleteTexture(tx_id) on the currently set context.
 void doneCurrent()
          Makes no GL context the current context.
 boolean doubleBuffer()
          Returns true if the contained GL rendering context has double buffering; otherwise returns false.
 boolean event(QEvent arg__1)
          

This is the main event handler; it handles event arg__1.

 QGLFormat format()
          Returns the format of the contained GL rendering context.
static QGLWidget fromNativePointer(QNativePointer nativePointer)
          This function returns the QGLWidget instance pointed to by nativePointer
protected  void glDraw()
          Executes the virtual function paintGL.
protected  void glInit()
          Initializes OpenGL for this widget's context.
 QImage grabFrameBuffer()
          Equivalent to grabFrameBuffer(false).
 QImage grabFrameBuffer(boolean withAlpha)
          Returns an image of the frame buffer.
protected  void initializeGL()
          This virtual function is called once before the first call to paintGL or resizeGL, and then once whenever the widget has been assigned a new QGLContext.
protected  void initializeOverlayGL()
          This virtual function is used in the same manner as initializeGL except that it operates on the widget's overlay context instead of the widget's main context.
 boolean isSharing()
          Returns true if this widget's GL context is shared with another GL context, otherwise false is returned.
 boolean isValid()
          Returns true if the widget has a valid GL rendering context; otherwise returns false.
 void makeCurrent()
          Makes this widget the current widget for OpenGL operations, i.e. makes the widget's rendering context the current OpenGL rendering context.
 void makeOverlayCurrent()
          Makes the overlay context of this widget current.
 QGLContext overlayContext()
          Returns the overlay context of this widget, or 0 if this widget has no overlay.
 QPaintEngine paintEngine()
          

Returns the widget's paint engine.

protected  void paintEvent(QPaintEvent arg__1)
          Handles paint events passed in the arg__1 parameter.
protected  void paintGL()
          This virtual function is called whenever the widget needs to be painted.
protected  void paintOverlayGL()
          This virtual function is used in the same manner as paintGL except that it operates on the widget's overlay context instead of the widget's main context.
 void qglClearColor(QColor c)
          Convenience function for specifying the clearing color to OpenGL.
 void qglColor(QColor c)
          Convenience function for specifying a drawing color to OpenGL.
 QPixmap renderPixmap()
          Equivalent to renderPixmap(0, 0, false).
 QPixmap renderPixmap(int w)
          Equivalent to renderPixmap(w, 0, false).
 QPixmap renderPixmap(int w, int h)
          Equivalent to renderPixmap(w, h, false).
 QPixmap renderPixmap(int w, int h, boolean useContext)
          Renders the current scene on a pixmap and returns the pixmap.
 void renderText(double x, double y, double z, java.lang.String str)
          Equivalent to renderText(x, y, z, str, QFont(), 2000).
 void renderText(double x, double y, double z, java.lang.String str, QFont fnt)
          Equivalent to renderText(x, y, z, str, fnt, 2000).
 void renderText(double x, double y, double z, java.lang.String str, QFont fnt, int listBase)
          x, y and z are specified in scene or object coordinates relative to the currently set projection and model matrices.
 void renderText(int x, int y, java.lang.String str)
          Equivalent to renderText(x, y, str, QFont(), 2000).
 void renderText(int x, int y, java.lang.String str, QFont fnt)
          Equivalent to renderText(x, y, str, fnt, 2000).
 void renderText(int x, int y, java.lang.String str, QFont fnt, int listBase)
          Renders the string str into the GL context of this widget.
protected  void resizeEvent(QResizeEvent arg__1)
          Handles resize events that are passed in the arg__1 parameter.
protected  void resizeGL(int w, int h)
          This virtual function is called whenever the widget has been resized.
protected  void resizeOverlayGL(int w, int h)
          This virtual function is used in the same manner as paintGL except that it operates on the widget's overlay context instead of the widget's main context.
protected  void setAutoBufferSwap(boolean on)
          If on is true automatic GL buffer swapping is switched on; otherwise it is switched off.
 void setColormap(QGLColormap map)
          Set the colormap for this widget to map.
 void swapBuffers()
          Swaps the screen contents with an off-screen buffer.
 void updateGL()
          Updates the widget by calling glDraw.
 void updateOverlayGL()
          Updates the widget's overlay (if any).
 
Methods inherited from class com.trolltech.qt.gui.QWidget
acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, changeEvent, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, closeEvent, contentsRect, contextMenuEvent, contextMenuPolicy, createWinId, cursor, depth, destroy, destroy, destroy, devType, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, ensurePolished, enterEvent, focusInEvent, focusNextChild, focusNextPrevChild, focusOutEvent, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, hasFocus, hasMouseTracking, height, heightForWidth, heightMM, hide, hideEvent, inputContext, inputMethodEvent, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, keyPressEvent, keyReleaseEvent, layout, layoutDirection, leaveEvent, locale, logicalDpiX, logicalDpiY, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumSizeHint, minimumWidth, mouseDoubleClickEvent, mouseGrabber, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, move, move, moveEvent, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, overrideWindowState, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, render, repaint, repaint, repaint, repaint, resetInputContext, resize, resize, restoreGeometry, saveGeometry, scroll, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setBaseSize, setContentsMargins, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedSize, setFixedWidth, setFocus, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGeometry, setHidden, setInputContext, setLayout, setLayoutDirection, setLocale, setMask, setMask, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setParent, setParent, setShortcutAutoRepeat, setShortcutAutoRepeat, setShortcutEnabled, setShortcutEnabled, setSizeIncrement, setSizeIncrement, setSizePolicy, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setVisible, setWhatsThis, setWindowFlags, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowState, setWindowTitle, show, showEvent, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeHint, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, underMouse, unsetCursor, unsetLayoutDirection, unsetLocale, update, update, update, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, wheelEvent, width, widthMM, window, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QGLWidget

public QGLWidget(QGLContext context,
                 QWidget parent,
                 QGLWidget shareWidget)

Equivalent to QGLWidget(context, parent, shareWidget, 0).


QGLWidget

public QGLWidget(QGLContext context,
                 QWidget parent)

Equivalent to QGLWidget(context, parent, 0, 0).


QGLWidget

public QGLWidget(QGLContext context)

Equivalent to QGLWidget(context, 0, 0, 0).


QGLWidget

public QGLWidget(QGLContext context,
                 QWidget parent,
                 QGLWidget shareWidget,
                 Qt.WindowFlags f)

Constructs an OpenGL widget with parent parent.

The context argument is a pointer to the QGLContext that you wish to be bound to this widget. This allows you to pass in your own QGLContext sub-classes.

The widget will be invalid if the system has no OpenGL support.

The parent and widget flag, f, arguments are passed to the QWidget constructor.

If shareWidget is a valid QGLWidget, this widget will share OpenGL display lists and texture objects with shareWidget. But if shareWidget and this widget have different formats, sharing might not be possible. You can check whether sharing is in effect by calling isSharing.

The initialization of OpenGL rendering state, etc. should be done by overriding the initializeGL function, rather than in the constructor of your QGLWidget subclass.

See Also:
QGLFormat::defaultFormat, isValid

QGLWidget

public QGLWidget(QGLFormat format,
                 QWidget parent,
                 QGLWidget shareWidget)

Equivalent to QGLWidget(format, parent, shareWidget, 0).


QGLWidget

public QGLWidget(QGLFormat format,
                 QWidget parent)

Equivalent to QGLWidget(format, parent, 0, 0).


QGLWidget

public QGLWidget(QGLFormat format)

Equivalent to QGLWidget(format, 0, 0, 0).


QGLWidget

public QGLWidget(QGLFormat format,
                 QWidget parent,
                 QGLWidget shareWidget,
                 Qt.WindowFlags f)

Constructs an OpenGL widget with parent parent.

The format argument specifies the desired rendering options. 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.

The widget will be invalid if the system has no OpenGL support.

The parent and widget flag, f, arguments are passed to the QWidget constructor.

If shareWidget is a valid QGLWidget, this widget will share OpenGL display lists and texture objects with shareWidget. But if shareWidget and this widget have different formats, sharing might not be possible. You can check whether sharing is in effect by calling isSharing.

The initialization of OpenGL rendering state, etc. should be done by overriding the initializeGL function, rather than in the constructor of your QGLWidget subclass.

See Also:
QGLFormat::defaultFormat, isValid

QGLWidget

public QGLWidget(QWidget parent,
                 QGLWidget shareWidget)

Equivalent to QGLWidget(parent, shareWidget, 0).


QGLWidget

public QGLWidget(QWidget parent)

Equivalent to QGLWidget(parent, 0, 0).


QGLWidget

public QGLWidget()

Equivalent to QGLWidget(0, 0, 0).


QGLWidget

public QGLWidget(QWidget parent,
                 QGLWidget shareWidget,
                 Qt.WindowFlags f)

Constructs an OpenGL widget with a parent widget.

The default format is used. The widget will be invalid if the system has no OpenGL support.

The parent and widget flag, f, arguments are passed to the QWidget constructor.

If shareWidget is a valid QGLWidget, this widget will share OpenGL display lists and texture objects with shareWidget. But if shareWidget and this widget have different formats, sharing might not be possible. You can check whether sharing is in effect by calling isSharing.

The initialization of OpenGL rendering state, etc. should be done by overriding the initializeGL function, rather than in the constructor of your QGLWidget subclass.

See Also:
QGLFormat::defaultFormat, Example
Method Detail

autoBufferSwap

protected final boolean autoBufferSwap()

Returns true if the widget is doing automatic GL buffer swapping; otherwise returns false.

See Also:
setAutoBufferSwap

bindTexture

public final int bindTexture(QImage image,
                             int target)

Equivalent to bindTexture(image, target, GL_RGBA).


bindTexture

public final int bindTexture(QImage image)

Equivalent to bindTexture(image, GL_TEXTURE_2D, GL_RGBA).


bindTexture

public final int bindTexture(QImage image,
                             int target,
                             int format)

Calls QGLContext:::bindTexture(image, target, format) on the currently set context.

See Also:
deleteTexture

bindTexture

public final int bindTexture(java.lang.String fileName)

Calls QGLContext::bindTexture(fileName) on the currently set context.

See Also:
deleteTexture

bindTexture

public final int bindTexture(QPixmap pixmap,
                             int target)

Equivalent to bindTexture(pixmap, target, GL_RGBA).


bindTexture

public final int bindTexture(QPixmap pixmap)

Equivalent to bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA).


bindTexture

public final int bindTexture(QPixmap pixmap,
                             int target,
                             int format)

Calls QGLContext:::bindTexture(pixmap, target, format) on the currently set context.

See Also:
deleteTexture

colormap

public final QGLColormap colormap()

Returns the colormap for this widget.

Usually it is only top-level widgets that can have different colormaps installed. Asking for the colormap of a child widget will return the colormap for the child's top-level widget.

If no colormap has been set for this widget, the QColormap returned will be empty.

See Also:
setColormap

context

public final QGLContext context()

Returns the context of this widget.

It is possible that the context is not valid (see isValid), for example, if the underlying hardware does not support the format attributes that were requested.


deleteTexture

public final void deleteTexture(int tx_id)

Calls QGLContext::deleteTexture(tx_id) on the currently set context.

See Also:
bindTexture

doneCurrent

public final void doneCurrent()

Makes no GL context the current context. Normally, you do not need to call this function; QGLContext calls it as necessary. However, it may be useful in multithreaded environments.


doubleBuffer

public final boolean doubleBuffer()

Returns true if the contained GL rendering context has double buffering; otherwise returns false.

See Also:
QGLFormat::doubleBuffer

format

public final QGLFormat format()

Returns the format of the contained GL rendering context.


grabFrameBuffer

public final QImage grabFrameBuffer()

Equivalent to grabFrameBuffer(false).


grabFrameBuffer

public final QImage grabFrameBuffer(boolean withAlpha)

Returns an image of the frame buffer. If withAlpha is true the alpha channel is included.

Depending on your hardware, you can explicitly select which color buffer to grab with a glReadBuffer() call before calling this function.


isSharing

public final boolean isSharing()

Returns true if this widget's GL context is shared with another GL context, otherwise false is returned. Context sharing might not be possible if the QGLWidgets use different formats.

See Also:
format

isValid

public final boolean isValid()

Returns true if the widget has a valid GL rendering context; otherwise returns false. A widget will be invalid if the system has no OpenGL support.


makeCurrent

public final void makeCurrent()

Makes this widget the current widget for OpenGL operations, i.e. makes the widget's rendering context the current OpenGL rendering context.


makeOverlayCurrent

public final void makeOverlayCurrent()

Makes the overlay context of this widget current. Use this if you need to issue OpenGL commands to the overlay context outside of initializeOverlayGL, resizeOverlayGL, and paintOverlayGL.

Does nothing if this widget has no overlay.

See Also:
makeCurrent

overlayContext

public final QGLContext overlayContext()

Returns the overlay context of this widget, or 0 if this widget has no overlay.

See Also:
context

qglClearColor

public final void qglClearColor(QColor c)

Convenience function for specifying the clearing color to OpenGL. Calls glClearColor (in RGBA mode) or glClearIndex (in color-index mode) with the color c. Applies to this widgets GL context.

See Also:
qglColor, QGLContext::currentContext, QColor

qglColor

public final void qglColor(QColor c)

Convenience function for specifying a drawing color to OpenGL. Calls glColor4 (in RGBA mode) or glIndex (in color-index mode) with the color c. Applies to this widgets GL context.

See Also:
qglClearColor, QGLContext::currentContext, QColor

renderPixmap

public final QPixmap renderPixmap(int w,
                                  int h)

Equivalent to renderPixmap(w, h, false).


renderPixmap

public final QPixmap renderPixmap(int w)

Equivalent to renderPixmap(w, 0, false).


renderPixmap

public final QPixmap renderPixmap()

Equivalent to renderPixmap(0, 0, false).


renderPixmap

public final QPixmap renderPixmap(int w,
                                  int h,
                                  boolean useContext)

Renders the current scene on a pixmap and returns the pixmap.

You can use this method on both visible and invisible QGLWidgets.

This method will create a pixmap and a temporary QGLContext to render on the pixmap. It will then call initializeGL, resizeGL, and paintGL on this context. Finally, the widget's original GL context is restored.

The size of the pixmap will be w pixels wide and h pixels high unless one of these parameters is 0 (the default), in which case the pixmap will have the same size as the widget.

If useContext is true, this method will try to be more efficient by using the existing GL context to render the pixmap. The default is false. Only use true if you understand the risks. Note that under Windows a temporary context has to be created and usage of the useContext parameter is not supported.

Overlays are not rendered onto the pixmap.

If the GL rendering context and the desktop have different bit depths, the result will most likely look surprising.

Note that the creation of display lists, modifications of the view frustum etc. should be done from within initializeGL. If this is not done, the temporary QGLContext will not be initialized properly, and the rendered pixmap may be incomplete/corrupted.


renderText

public final void renderText(int x,
                             int y,
                             java.lang.String str,
                             QFont fnt)

Equivalent to renderText(x, y, str, fnt, 2000).


renderText

public final void renderText(int x,
                             int y,
                             java.lang.String str)

Equivalent to renderText(x, y, str, QFont(), 2000).


renderText

public final void renderText(int x,
                             int y,
                             java.lang.String str,
                             QFont fnt,
                             int listBase)

Renders the string str into the GL context of this widget.

x and y are specified in window coordinates, with the origin in the upper left-hand corner of the window. If fnt is not specified, the currently set application font will be used to render the string. To change the color of the rendered text you can use the glColor() call (or the qglColor convenience function), just before the renderText call.

The listBase parameter is obsolete and will be removed in a future version of Qt.


renderText

public final void renderText(double x,
                             double y,
                             double z,
                             java.lang.String str,
                             QFont fnt)

Equivalent to renderText(x, y, z, str, fnt, 2000).


renderText

public final void renderText(double x,
                             double y,
                             double z,
                             java.lang.String str)

Equivalent to renderText(x, y, z, str, QFont(), 2000).


renderText

public final void renderText(double x,
                             double y,
                             double z,
                             java.lang.String str,
                             QFont fnt,
                             int listBase)

x, y and z are specified in scene or object coordinates relative to the currently set projection and model matrices. This can be useful if you want to annotate models with text labels and have the labels move with the model as it is rotated etc.

Note that this function only works properly if GL_DEPTH_TEST is enabled, and you have a properly initialized depth buffer.


setAutoBufferSwap

protected final void setAutoBufferSwap(boolean on)

If on is true automatic GL buffer swapping is switched on; otherwise it is switched off.

If on is true and the widget is using a double-buffered format, the background and foreground GL buffers will automatically be swapped after each paintGL call.

The buffer auto-swapping is on by default.

See Also:
autoBufferSwap, doubleBuffer, swapBuffers

setColormap

public final void setColormap(QGLColormap map)

Set the colormap for this widget to map. Usually it is only top-level widgets that can have colormaps installed.

See Also:
colormap

swapBuffers

public final void swapBuffers()

Swaps the screen contents with an off-screen buffer. This only works if the widget's format specifies double buffer mode.

Normally, there is no need to explicitly call this function because it is done automatically after each widget repaint, i.e. each time after paintGL has been executed.

See Also:
doubleBuffer, setAutoBufferSwap, QGLFormat::setDoubleBuffer

event

public boolean event(QEvent arg__1)

This is the main event handler; it handles event arg__1. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.

Key press and release events are treated differently from other events. event checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event calls keyPressEvent.

Mouse and tablet event handling is also slightly special: only when the widget is enabled, event will call the specialized handlers such as mousePressEvent; otherwise it will discard the event.

This function returns true if the event was recognized, otherwise it returns false. If the recognized event was accepted (see QEvent::accepted), any further processing such as event propagation to the parent widget stops.

Overrides:
event in class QWidget
See Also:
closeEvent, focusInEvent, focusOutEvent, enterEvent, keyPressEvent, keyReleaseEvent, leaveEvent, mouseDoubleClickEvent, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, moveEvent, paintEvent, resizeEvent, QObject::event, QObject::timerEvent

glDraw

protected void glDraw()

Executes the virtual function paintGL.

The widget's rendering context will become the current context and initializeGL will be called if it hasn't already been called.


glInit

protected void glInit()

Initializes OpenGL for this widget's context. Calls the virtual function initializeGL.


initializeGL

protected void initializeGL()

This virtual function is called once before the first call to paintGL or resizeGL, and then once whenever the widget has been assigned a new QGLContext. Reimplement it in a subclass.

This function should set up any required OpenGL context rendering flags, defining display lists, etc.

There is no need to call makeCurrent because this has already been done when this function is called.


initializeOverlayGL

protected void initializeOverlayGL()

This virtual function is used in the same manner as initializeGL except that it operates on the widget's overlay context instead of the widget's main context. This means that initializeOverlayGL is called once before the first call to paintOverlayGL or resizeOverlayGL. Reimplement it in a subclass.

This function should set up any required OpenGL context rendering flags, defining display lists, etc. for the overlay context.

There is no need to call makeOverlayCurrent because this has already been done when this function is called.


paintEngine

public QPaintEngine paintEngine()

Returns the widget's paint engine.

Specified by:
paintEngine in interface QPaintDeviceInterface
Overrides:
paintEngine in class QWidget

paintEvent

protected void paintEvent(QPaintEvent arg__1)

Handles paint events passed in the arg__1 parameter. Will cause the virtual paintGL function to be called.

The widget's rendering context will become the current context and initializeGL will be called if it hasn't already been called.

Overrides:
paintEvent in class QWidget
See Also:
event, repaint, update, QPainter, QPixmap, QPaintEvent, Analog Clock Example

paintGL

protected void paintGL()

This virtual function is called whenever the widget needs to be painted. Reimplement it in a subclass.

There is no need to call makeCurrent because this has already been done when this function is called.


paintOverlayGL

protected void paintOverlayGL()

This virtual function is used in the same manner as paintGL except that it operates on the widget's overlay context instead of the widget's main context. This means that paintOverlayGL is called whenever the widget's overlay needs to be painted. Reimplement it in a subclass.

There is no need to call makeOverlayCurrent because this has already been done when this function is called.


resizeEvent

protected void resizeEvent(QResizeEvent arg__1)

Handles resize events that are passed in the arg__1 parameter. Calls the virtual function resizeGL.

Overrides:
resizeEvent in class QWidget
See Also:
moveEvent, event, resize, QResizeEvent, paintEvent, Example

resizeGL

protected void resizeGL(int w,
                        int h)

This virtual function is called whenever the widget has been resized. The new size is passed in w and h. Reimplement it in a subclass.

There is no need to call makeCurrent because this has already been done when this function is called.


resizeOverlayGL

protected void resizeOverlayGL(int w,
                               int h)

This virtual function is used in the same manner as paintGL except that it operates on the widget's overlay context instead of the widget's main context. This means that resizeOverlayGL is called whenever the widget has been resized. The new size is passed in w and h. Reimplement it in a subclass.

There is no need to call makeOverlayCurrent because this has already been done when this function is called.


updateGL

public void updateGL()

Updates the widget by calling glDraw.


updateOverlayGL

public void updateOverlayGL()

Updates the widget's overlay (if any). Will cause the virtual function paintOverlayGL to be executed.

The widget's rendering context will become the current context and initializeGL will be called if it hasn't already been called.


convertToGLFormat

public static QImage convertToGLFormat(QImage img)

Converts the image img into the unnamed format expected by OpenGL functions such as glTexImage2D(). The returned image is not usable as a QImage, but QImage::width(), QImage::height() and QImage::bits() may be used with OpenGL.


fromNativePointer

public static QGLWidget fromNativePointer(QNativePointer nativePointer)
This function returns the QGLWidget instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

Qt Jambi Home