|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QWidget
com.trolltech.qt.opengl.QGLWidget
public class QGLWidget
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:
paintGL()
- Renders the OpenGL
scene. Gets called whenever the widget needs to be updated.resizeGL()
- Sets up the OpenGL
viewport, projection, etc. Gets called whenever the the widget has been resized (and also when it is shown for the first time because all newly created widgets get a resize event automatically).initializeGL()
- Sets up the OpenGL
rendering context, defines display lists, etc. Gets called once before the first time resizeGL()
or paintGL()
is called.QGLWidget
subclass might look: class MyGLDrawer extends QGLWidget { GL func = null; GLContext ctx = null; public MyGLDrawer(QWidget parent) { super(parent); } protected void initializeGL() { GLDrawableFactory factory = GLDrawableFactory.getFactory(); ctx = factory.createExternalGLContext(); func = ctx.getGL(); // Set up the rendering context, define display lists etc.: // ... func.glClearColor(0, 0, 0, 0); func.glEnable(GL.GL_DEPTH_TEST); // ... } protected void resizeGL(int w, int h) { // setup viewport, projection etc.: func.glViewport(0, 0, w, h); // ... func.glFrustum(0.0, 1.0, 0.0, 1.0, 1.0, 2.0); // ... } protected void paintGL() { // draw the scene: // ... func.glRotatef(10, 0, 1, 0); func.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 1); func.glBegin(GL.GL_QUADS); func.glVertex3f(1, 1, 1); func.glVertex3f(1, 2, 1); // ... func.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).
Note that under Windows, the QGLContext
belonging to a QGLWidget
has to be recreated when the QGLWidget
is reparented. This is necessary due to limitations on the Windows platform. This will most likely cause problems for users that have subclassed and installed their own QGLContext
on a QGLWidget
. It is possible to work around this issue but putting the QGLWidget
inside a dummy widget and then reparenting the dummy widget, instead of the QGLWidget
. This will side-step the issue altogether, and is what we recommend for users that need this kind of functionality.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:
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:
QGLWidget::initializeGL()
and QGLWidget::resizeGL()
to set up the OpenGL
state and provide a perspective transformation.QGLWidget::paintGL()
to paint the 3D scene, calling only OpenGL
functions to draw on the widget.QGLWidget
subclass, it is necessary to reimplement QGLWidget::paintEvent()
and do the following: QPainter
object.QPainter::begin()
function.QPainter
's member functions.QPainter::end()
to finish painting.OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other countries.
QGLPixelBuffer
, Hello GL Example, 2D Painting Example, Overpainting Example, and Grabber 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, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Constructor Summary | |
---|---|
QGLWidget()
Constructs an OpenGL widget with a parent widget. |
|
QGLWidget(QGLContext context)
Constructs an OpenGL widget with parent parent. |
|
QGLWidget(QGLContext context,
QWidget parent)
Constructs an OpenGL widget with parent parent. |
|
QGLWidget(QGLContext context,
QWidget parent,
QGLWidget shareWidget)
Constructs an OpenGL widget with parent parent. |
|
QGLWidget(QGLContext context,
QWidget parent,
QGLWidget shareWidget,
Qt.WindowFlags f)
Constructs an OpenGL widget with parent parent. |
|
QGLWidget(QGLContext context,
QWidget parent,
QGLWidget shareWidget,
Qt.WindowType[] f)
Constructs an OpenGL widget with parent parent. |
|
QGLWidget(QGLFormat format)
Constructs an OpenGL widget with parent parent. |
|
QGLWidget(QGLFormat format,
QWidget parent)
Constructs an OpenGL widget with parent parent. |
|
QGLWidget(QGLFormat format,
QWidget parent,
QGLWidget shareWidget)
Constructs an OpenGL widget with parent parent. |
|
QGLWidget(QGLFormat format,
QWidget parent,
QGLWidget shareWidget,
Qt.WindowFlags f)
Constructs an OpenGL widget with parent parent. |
|
QGLWidget(QGLFormat format,
QWidget parent,
QGLWidget shareWidget,
Qt.WindowType[] f)
Constructs an OpenGL widget with parent parent. |
|
QGLWidget(QWidget parent)
Constructs an OpenGL widget with a parent widget. |
|
QGLWidget(QWidget parent,
QGLWidget shareWidget)
Constructs an OpenGL widget with a parent widget. |
|
QGLWidget(QWidget parent,
QGLWidget shareWidget,
Qt.WindowFlags f)
Constructs an OpenGL widget with a parent widget. |
|
QGLWidget(QWidget parent,
QGLWidget shareWidget,
Qt.WindowType[] 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)
Calls QGLContext:: :bindTexture (image, target, format) on the currently set context. |
int |
bindTexture(QImage image,
int target)
Calls QGLContext:: :bindTexture (image, target, format) on the currently set context. |
int |
bindTexture(QImage image,
int target,
int format)
Calls QGLContext:: :bindTexture (image, target, format) on the currently set context. |
int |
bindTexture(QPixmap pixmap)
Calls QGLContext.::bindTexture(pixmap, target, format) on the currently set context. |
int |
bindTexture(QPixmap pixmap,
int target)
Calls QGLContext.::bindTexture(pixmap, target, format) on the currently set context. |
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 (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. |
void |
drawTexture(QPointF point,
int textureId)
Draws the given texture, textureId, at the given point in OpenGL model space. |
void |
drawTexture(QPointF point,
int textureId,
int textureTarget)
Draws the given texture, textureId, at the given point in OpenGL model space. |
void |
drawTexture(QRectF target,
int textureId)
Draws the given texture, textureId to the given target rectangle, target, in OpenGL model space. |
void |
drawTexture(QRectF target,
int textureId,
int textureTarget)
Draws the given texture, textureId to the given target rectangle, target, in OpenGL model space. |
QGLFormat |
format()
Returns the format of the contained GL rendering context. |
static QGLWidget |
fromNativePointer(QNativePointer nativePointer)
|
protected void |
glDraw()
Executes the virtual function paintGL() . |
protected void |
glInit()
Initializes OpenGL for this widget's context. |
QImage |
grabFrameBuffer()
Returns an image of the frame buffer. |
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. |
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. |
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()
Renders the current scene on a pixmap and returns the pixmap. |
QPixmap |
renderPixmap(int w)
Renders the current scene on a pixmap and returns the pixmap. |
QPixmap |
renderPixmap(int w,
int h)
Renders the current scene on a pixmap and returns the pixmap. |
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)
x, y and z are specified in scene or object coordinates relative to the currently set projection and model matrices. |
void |
renderText(double x,
double y,
double z,
java.lang.String str,
QFont fnt)
x, y and z are specified in scene or object coordinates relative to the currently set projection and model matrices. |
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)
Renders the string str into the GL context of this widget. |
void |
renderText(int x,
int y,
java.lang.String str,
QFont fnt)
Renders the string str into the GL context of this widget. |
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 |
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 cmap. |
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.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QGLWidget(QGLContext context, QWidget parent, QGLWidget shareWidget, Qt.WindowType[] f)
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.
QGLFormat::defaultFormat()
, and isValid()
.
public QGLWidget(QGLContext context, QWidget parent, QGLWidget shareWidget)
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.
QGLFormat::defaultFormat()
, and isValid()
.
public QGLWidget(QGLContext context, QWidget 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.
QGLFormat::defaultFormat()
, and isValid()
.
public QGLWidget(QGLContext context)
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.
QGLFormat::defaultFormat()
, and isValid()
.
public QGLWidget(QGLContext context, QWidget parent, QGLWidget shareWidget, Qt.WindowFlags f)
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.
QGLFormat::defaultFormat()
, and isValid()
.
public QGLWidget(QWidget parent, QGLWidget shareWidget, Qt.WindowType[] f)
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.
QGLFormat::defaultFormat()
, and Textures Example.
public QGLWidget(QWidget parent, QGLWidget shareWidget)
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.
QGLFormat::defaultFormat()
, and Textures Example.
public QGLWidget(QWidget parent)
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.
QGLFormat::defaultFormat()
, and Textures Example.
public QGLWidget()
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.
QGLFormat::defaultFormat()
, and Textures Example.
public QGLWidget(QWidget parent, QGLWidget shareWidget, Qt.WindowFlags f)
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.
QGLFormat::defaultFormat()
, and Textures Example.
public QGLWidget(QGLFormat format, QWidget parent, QGLWidget shareWidget, Qt.WindowType[] f)
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.
QGLFormat::defaultFormat()
, and isValid()
.
public QGLWidget(QGLFormat format, QWidget parent, QGLWidget shareWidget)
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.
QGLFormat::defaultFormat()
, and isValid()
.
public QGLWidget(QGLFormat format, QWidget 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.
QGLFormat::defaultFormat()
, and isValid()
.
public QGLWidget(QGLFormat format)
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.
QGLFormat::defaultFormat()
, and isValid()
.
public QGLWidget(QGLFormat format, QWidget parent, QGLWidget shareWidget, Qt.WindowFlags f)
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.
QGLFormat::defaultFormat()
, and isValid()
.
Method Detail |
---|
protected final boolean autoBufferSwap()
setAutoBufferSwap()
.
public final int bindTexture(QImage image, int target)
QGLContext::
:bindTexture
(image, target, format) on the currently set context. deleteTexture()
.
public final int bindTexture(QImage image)
QGLContext::
:bindTexture
(image, target, format) on the currently set context. deleteTexture()
.
public final int bindTexture(QImage image, int target, int format)
QGLContext::
:bindTexture
(image, target, format) on the currently set context. deleteTexture()
.
public final int bindTexture(QPixmap pixmap, int target)
deleteTexture()
.
public final int bindTexture(QPixmap pixmap)
deleteTexture()
.
public final int bindTexture(QPixmap pixmap, int target, int format)
deleteTexture()
.
public final int bindTexture(java.lang.String fileName)
deleteTexture()
.
public final QGLColormap colormap()
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.
setColormap()
.
public final QGLContext context()
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.
public final void deleteTexture(int tx_id)
QGLContext::deleteTexture
(id) on the currently set context. bindTexture()
.
public final void doneCurrent()
QGLContext
calls it as necessary. However, it may be useful in multithreaded environments.
public final boolean doubleBuffer()
QGLFormat::doubleBuffer()
.
public final void drawTexture(QPointF point, int textureId)
Equivalent to the corresponding QGLContext::drawTexture()
.
public final void drawTexture(QPointF point, int textureId, int textureTarget)
Equivalent to the corresponding QGLContext::drawTexture()
.
public final void drawTexture(QRectF target, int textureId)
OpenGL
model space. The textureTarget should be a 2D texture target. Equivalent to the corresponding QGLContext::drawTexture()
.
public final void drawTexture(QRectF target, int textureId, int textureTarget)
OpenGL
model space. The textureTarget should be a 2D texture target. Equivalent to the corresponding QGLContext::drawTexture()
.
public final QGLFormat format()
public final QImage grabFrameBuffer()
Depending on your hardware, you can explicitly select which color buffer to grab with a glReadBuffer()
call before calling this function.
public final QImage grabFrameBuffer(boolean withAlpha)
Depending on your hardware, you can explicitly select which color buffer to grab with a glReadBuffer()
call before calling this function.
public final boolean isSharing()
QGLWidgets
use different formats. format()
.
public final boolean isValid()
OpenGL support
.
public final void makeCurrent()
OpenGL
operations, i.e. makes the widget's rendering context the current OpenGL
rendering context.
public final void makeOverlayCurrent()
OpenGL
commands to the overlay context outside of initializeOverlayGL()
, resizeOverlayGL()
, and paintOverlayGL()
. Does nothing if this widget has no overlay.
makeCurrent()
.
public final QGLContext overlayContext()
context()
.
public final void qglClearColor(QColor c)
OpenGL
. Calls glClearColor
(in RGBA mode) or glClearIndex
(in color-index mode) with the color c. Applies to this widgets GL context. qglColor()
, QGLContext::currentContext()
, and QColor
.
public final void qglColor(QColor c)
OpenGL
. Calls glColor4
(in RGBA mode) or glIndex
(in color-index mode) with the color c. Applies to this widgets GL context. qglClearColor()
, QGLContext::currentContext()
, and QColor
.
public final QPixmap renderPixmap(int w, int h)
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.
public final QPixmap renderPixmap(int w)
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.
public final QPixmap renderPixmap()
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.
public final QPixmap renderPixmap(int w, int h, boolean useContext)
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.
public final void renderText(double x, double y, double z, java.lang.String str, QFont fnt)
public final void renderText(double x, double y, double z, java.lang.String str)
public final void renderText(double x, double y, double z, java.lang.String str, QFont fnt, int listBase)
public final void renderText(int x, int y, java.lang.String str, QFont fnt)
x and y are specified in window coordinates, with the origin in the upper left-hand corner of the window. If font 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.
Note: This function clears the stencil buffer.
public final void renderText(int x, int y, java.lang.String str)
x and y are specified in window coordinates, with the origin in the upper left-hand corner of the window. If font 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.
Note: This function clears the stencil buffer.
public final void renderText(int x, int y, java.lang.String str, QFont fnt, int listBase)
x and y are specified in window coordinates, with the origin in the upper left-hand corner of the window. If font 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.
Note: This function clears the stencil buffer.
protected final void setAutoBufferSwap(boolean on)
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.
autoBufferSwap()
, doubleBuffer()
, and swapBuffers()
.
public final void setColormap(QGLColormap map)
colormap()
.
public final void swapBuffers()
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.
doubleBuffer()
, setAutoBufferSwap()
, and QGLFormat::setDoubleBuffer()
.
protected void glDraw()
paintGL()
. The widget's rendering context will become the current context and initializeGL()
will be called if it hasn't already been called.
protected void glInit()
OpenGL
for this widget's context. Calls the virtual function initializeGL()
.
protected void initializeGL()
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.
protected void initializeOverlayGL()
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.
protected void paintGL()
There is no need to call makeCurrent()
because this has already been done when this function is called.
protected void paintOverlayGL()
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.
protected void resizeGL(int w, int h)
There is no need to call makeCurrent()
because this has already been done when this function is called.
protected void resizeOverlayGL(int w, int h)
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 width and height. Reimplement it in a subclass. There is no need to call makeOverlayCurrent()
because this has already been done when this function is called.
public void updateGL()
glDraw()
.
public void updateOverlayGL()
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.
public static QImage convertToGLFormat(QImage img)
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
. The GL format used is GL_RGBA.
public static QGLWidget fromNativePointer(QNativePointer nativePointer)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |