TQGLWidget provides functionality for displaying OpenGL<sup>*</sup> graphics integrated into a TQt application. It is very simple to use. You inherit from it and use the subclass like any other TQWidget, except that instead of drawing the widget's contents using TQPainter etc. you use the standard OpenGL rendering commands.
paintGL() - Renders the OpenGL scene. Gets called whenever the widget needs to be updated.
.TP
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).
.TP
initializeGL() - Sets up the OpenGL rendering context, defines display lists, etc. Gets called once before the first time resizeGL() or paintGL() is called.
// Set up the rendering context, define display lists etc.:
.br
...
.br
glClearColor( 0.0, 0.0, 0.0, 0.0 );
.br
glEnable(GL_DEPTH_TEST);
.br
...
.br
}
.br
.br
void resizeGL( int w, int h )
.br
{
.br
// setup viewport, projection etc.:
.br
glViewport( 0, 0, (GLint)w, (GLint)h );
.br
...
.br
glFrustum( ... );
.br
...
.br
}
.br
.br
void paintGL()
.br
{
.br
// draw the scene:
.br
...
.br
glRotatef( ... );
.br
glMaterialfv( ... );
.br
glBegin( GL_QUADS );
.br
glVertex3f( ... );
.br
glVertex3f( ... );
.br
...
.br
glEnd();
.br
...
.br
}
.br
.br
};
.br
.fi
.PP
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.
.PP
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.
If you want to use overlays, you specify it in the format. (Note: Overlay must be requested in the format passed to the TQGLWidget 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 TQt windows can also be used for overlays. See the examples/opengl/overlay_x11 example program for details.
If the \fIshareWidget\fR parameter points to a valid TQGLWidget, this widget will share OpenGL display lists with \fIshareWidget\fR. If this widget and \fIshareWidget\fR have different formats, display list sharing may fail. You can check whether display list sharing succeeded 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 TQGLWidget subclass.
The \fIcontext\fR argument is a pointer to the TQGLContext that you wish to be bound to this widget. This allows you to pass in your own TQGLContext sub-classes.
If the \fIshareWidget\fR parameter points to a valid TQGLWidget, this widget will share OpenGL display lists with \fIshareWidget\fR. If this widget and \fIshareWidget\fR have different formats, display list sharing may fail. You can check whether display list sharing succeeded 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 TQGLWidget subclass.
Constructs an OpenGL widget with parent \fIparent\fR, called \fIname\fR.
.PP
The \fIformat\fR argument specifies the desired rendering options. 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
The widget will be invalid if the system has no OpenGL support.
If the \fIshareWidget\fR parameter points to a valid TQGLWidget, this widget will share OpenGL display lists with \fIshareWidget\fR. If this widget and \fIshareWidget\fR have different formats, display list sharing may fail. You can check whether display list sharing succeeded 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 TQGLWidget subclass.
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.
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.
Converts the image \fIimg\fR into the unnamed format expected by OpenGL functions such as glTexImage2D(). The returned image is not usable as a TQImage, but TQImage::width(), TQImage::height() and TQImage::bits() may be used with OpenGL. The following few lines are from the texture example. Most of the code is irrelevant, so we just quote the relevant bits:
Note the dimension restrictions for texture images as described in the glTexImage2D() documentation. The width must be 2^m + 2*border and the height 2^n + 2*border where m and n are integers and border is either 0 or 1.
.PP
Another function in the same example uses \fItex1\fR with OpenGL.
Makes no GL context the current context. Normally, you do not need to call this function; TQGLContext calls it as necessary. However, it may be useful in multithreaded environments.
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 TQGLContext. Reimplement it in a subclass.
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.
Returns TRUE if display list sharing with another TQGLWidget was requested in the constructor, and the GL system was able to provide it; otherwise returns FALSE. The GL system may fail to provide display list sharing if the two TQGLWidgets use different formats.
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().
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.
.PP
There is no need to call makeOverlayCurrent() because this has already been done when this function is called.
Convenience function for specifying the clearing color to OpenGL. Calls glClearColor (in RGBA mode) or glClearIndex (in color-index mode) with the color \fIc\fR. Applies to the current GL context.
Convenience function for specifying a drawing color to OpenGL. Calls glColor3 (in RGBA mode) or glIndex (in color-index mode) with the color \fIc\fR. Applies to the current GL context.
This method will create a pixmap and a temporary TQGLContext 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 \fIw\fR pixels wide and \fIh\fR pixels high unless one of these parameters is 0 (the default), in which case the pixmap will have the same size as the widget.
.PP
If \fIuseContext\fR 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.
.PP
Overlays are not rendered onto the pixmap.
.PP
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 TQGLContext will not be initialized properly, and the rendered pixmap may be incomplete/corrupted.
.SH "void TQGLWidget::renderText ( int x, int y, const TQString & str, const TQFont & fnt = TQFont ( ), int listBase = 2000 )"
Renders the string \fIstr\fR into the GL context of this widget.
.PP
\fIx\fR and \fIy\fR are specified in window coordinates, with the origin in the upper left-hand corner of the window. If \fIfnt\fR 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. Note that if you have GL_LIGHTING enabled, the string will not appear in the color you want. You should therefore switch lighting off before using renderText().
.PP
\fIlistBase\fR specifies the index of the first display list that is generated by this function. The default value is 2000. 256 display lists will be generated, one for each of the first 256 characters in the font that is used to render the string. If several fonts are used in the same widget, the display lists for these fonts will follow the last generated list. You would normally not have to change this value unless you are using lists in the same range. The lists are deleted when the widget is destroyed.
.PP
Note: This function only works reliably with ASCII strings.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
\fIx\fR, \fIy\fR and \fIz\fR 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.
This virtual function is called whenever the widget has been resized. The new size is passed in \fIwidth\fR and \fIheight\fR. Reimplement it in a subclass.
.PP
There is no need to call makeCurrent() because this has already been done when this function is called.
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 \fIwidth\fR and \fIheight\fR. Reimplement it in a subclass.
.PP
There is no need to call makeOverlayCurrent() because this has already been done when this function is called.
If \fIon\fR is TRUE automatic GL buffer swapping is switched on; otherwise it is switched off.
.PP
If \fIon\fR 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.
.PP
The buffer auto-swapping is on by default.
.PP
See also autoBufferSwap(), doubleBuffer(), and swapBuffers().
Swaps the screen contents with an off-screen buffer. This only works if the widget's format specifies double buffer mode.
.PP
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.