source: trunk/doc/html/qglwidget.html

Last change on this file was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 33.2 KB
RevLine 
[190]1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/opengl/qgl.cpp:1126 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QGLWidget Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QGLWidget Class Reference<br><small>[<a href="opengl.html">OpenGL module</a>]</small></h1>
33
34<p>The QGLWidget class is a widget for rendering OpenGL graphics.
35<a href="#details">More...</a>
36<p><tt>#include &lt;<a href="qgl-h.html">qgl.h</a>&gt;</tt>
37<p>Inherits <a href="qwidget.html">QWidget</a> and <a href="qgl.html">QGL</a>.
38<p><a href="qglwidget-members.html">List of all member functions.</a>
39<h2>Public Members</h2>
40<ul>
41<li class=fn><a href="#QGLWidget"><b>QGLWidget</b></a> ( QWidget&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0, const&nbsp;QGLWidget&nbsp;*&nbsp;shareWidget = 0, WFlags&nbsp;f = 0 )</li>
42<li class=fn><a href="#QGLWidget-2"><b>QGLWidget</b></a> ( QGLContext&nbsp;*&nbsp;context, QWidget&nbsp;*&nbsp;parent, const&nbsp;char&nbsp;*&nbsp;name = 0, const&nbsp;QGLWidget&nbsp;*&nbsp;shareWidget = 0, WFlags&nbsp;f = 0 )</li>
43<li class=fn><a href="#QGLWidget-3"><b>QGLWidget</b></a> ( const&nbsp;QGLFormat&nbsp;&amp;&nbsp;format, QWidget&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0, const&nbsp;QGLWidget&nbsp;*&nbsp;shareWidget = 0, WFlags&nbsp;f = 0 )</li>
44<li class=fn><a href="#~QGLWidget"><b>~QGLWidget</b></a> ()</li>
45<li class=fn>void <a href="#qglColor"><b>qglColor</b></a> ( const&nbsp;QColor&nbsp;&amp;&nbsp;c ) const</li>
46<li class=fn>void <a href="#qglClearColor"><b>qglClearColor</b></a> ( const&nbsp;QColor&nbsp;&amp;&nbsp;c ) const</li>
47<li class=fn>bool <a href="#isValid"><b>isValid</b></a> () const</li>
48<li class=fn>bool <a href="#isSharing"><b>isSharing</b></a> () const</li>
49<li class=fn>virtual void <a href="#makeCurrent"><b>makeCurrent</b></a> ()</li>
50<li class=fn>void <a href="#doneCurrent"><b>doneCurrent</b></a> ()</li>
51<li class=fn>bool <a href="#doubleBuffer"><b>doubleBuffer</b></a> () const</li>
52<li class=fn>virtual void <a href="#swapBuffers"><b>swapBuffers</b></a> ()</li>
53<li class=fn>QGLFormat <a href="#format"><b>format</b></a> () const</li>
54<li class=fn>const QGLContext * <a href="#context"><b>context</b></a> () const</li>
55<li class=fn>virtual QPixmap <a href="#renderPixmap"><b>renderPixmap</b></a> ( int&nbsp;w = 0, int&nbsp;h = 0, bool&nbsp;useContext = FALSE )</li>
56<li class=fn>virtual QImage <a href="#grabFrameBuffer"><b>grabFrameBuffer</b></a> ( bool&nbsp;withAlpha = FALSE )</li>
57<li class=fn>virtual void <a href="#makeOverlayCurrent"><b>makeOverlayCurrent</b></a> ()</li>
58<li class=fn>const QGLContext * <a href="#overlayContext"><b>overlayContext</b></a> () const</li>
59<li class=fn>const QGLColormap &amp; <a href="#colormap"><b>colormap</b></a> () const</li>
60<li class=fn>void <a href="#setColormap"><b>setColormap</b></a> ( const&nbsp;QGLColormap&nbsp;&amp;&nbsp;cmap )</li>
61<li class=fn>void <a href="#renderText"><b>renderText</b></a> ( int&nbsp;x, int&nbsp;y, const&nbsp;QString&nbsp;&amp;&nbsp;str, const&nbsp;QFont&nbsp;&amp;&nbsp;fnt = QFont ( ), int&nbsp;listBase = 2000 )</li>
62<li class=fn>void <a href="#renderText-2"><b>renderText</b></a> ( double&nbsp;x, double&nbsp;y, double&nbsp;z, const&nbsp;QString&nbsp;&amp;&nbsp;str, const&nbsp;QFont&nbsp;&amp;&nbsp;fnt = QFont ( ), int&nbsp;listBase = 2000 )</li>
63</ul>
64<h2>Public Slots</h2>
65<ul>
66<li class=fn>virtual void <a href="#updateGL"><b>updateGL</b></a> ()</li>
67<li class=fn>virtual void <a href="#updateOverlayGL"><b>updateOverlayGL</b></a> ()</li>
68</ul>
69<h2>Static Public Members</h2>
70<ul>
71<li class=fn>QImage <a href="#convertToGLFormat"><b>convertToGLFormat</b></a> ( const&nbsp;QImage&nbsp;&amp;&nbsp;img )</li>
72</ul>
73<h2>Protected Members</h2>
74<ul>
75<li class=fn>virtual void <a href="#initializeGL"><b>initializeGL</b></a> ()</li>
76<li class=fn>virtual void <a href="#resizeGL"><b>resizeGL</b></a> ( int&nbsp;width, int&nbsp;height )</li>
77<li class=fn>virtual void <a href="#paintGL"><b>paintGL</b></a> ()</li>
78<li class=fn>virtual void <a href="#initializeOverlayGL"><b>initializeOverlayGL</b></a> ()</li>
79<li class=fn>virtual void <a href="#resizeOverlayGL"><b>resizeOverlayGL</b></a> ( int&nbsp;width, int&nbsp;height )</li>
80<li class=fn>virtual void <a href="#paintOverlayGL"><b>paintOverlayGL</b></a> ()</li>
81<li class=fn>void <a href="#setAutoBufferSwap"><b>setAutoBufferSwap</b></a> ( bool&nbsp;on )</li>
82<li class=fn>bool <a href="#autoBufferSwap"><b>autoBufferSwap</b></a> () const</li>
83<li class=fn>virtual void <a href="#paintEvent"><b>paintEvent</b></a> ( QPaintEvent * )</li>
84<li class=fn>virtual void <a href="#resizeEvent"><b>resizeEvent</b></a> ( QResizeEvent * )</li>
85<li class=fn>virtual void <a href="#glInit"><b>glInit</b></a> ()</li>
86<li class=fn>virtual void <a href="#glDraw"><b>glDraw</b></a> ()</li>
87</ul>
88<hr><a name="details"></a><h2>Detailed Description</h2>
89
90
91The QGLWidget class is a widget for rendering OpenGL graphics.
92
93<p>
94
95
96
97<p> QGLWidget provides functionality for displaying OpenGL<sup>*</sup>
98graphics integrated into a Qt application. It is very simple to
99use. You inherit from it and use the subclass like any other
100<a href="qwidget.html">QWidget</a>, except that instead of drawing the widget's contents
101using <a href="qpainter.html">QPainter</a> etc. you use the standard OpenGL rendering
102commands.
103<p> QGLWidget provides three convenient virtual functions that you can
104reimplement in your subclass to perform the typical OpenGL tasks:
105<p> <ul>
106<li> <a href="#paintGL">paintGL</a>() - Renders the OpenGL scene. Gets called whenever the widget
107needs to be updated.
108<li> <a href="#resizeGL">resizeGL</a>() - Sets up the OpenGL viewport, projection, etc. Gets
109called whenever the the widget has been resized (and also when it
110is shown for the first time because all newly created widgets get a
111resize event automatically).
112<li> <a href="#initializeGL">initializeGL</a>() - Sets up the OpenGL rendering context, defines display
113lists, etc. Gets called once before the first time resizeGL() or
114paintGL() is called.
115</ul>
116<p> Here is a rough outline of how a QGLWidget subclass might look:
117<p> <pre>
118 class MyGLDrawer : public QGLWidget
119 {
120 Q_OBJECT // must include this if you use Qt signals/slots
121
122 public:
123 MyGLDrawer( <a href="qwidget.html">QWidget</a> *parent, const char *name )
124 : QGLWidget(parent, name) {}
125
126 protected:
127
128 void initializeGL()
129 {
130 // Set up the rendering context, define display lists etc.:
131 ...
132 glClearColor( 0.0, 0.0, 0.0, 0.0 );
133 glEnable(GL_DEPTH_TEST);
134 ...
135 }
136
137 void resizeGL( int w, int h )
138 {
139 // setup viewport, projection etc.:
140 glViewport( 0, 0, (GLint)w, (GLint)h );
141 ...
142 glFrustum( ... );
143 ...
144 }
145
146 void paintGL()
147 {
148 // draw the scene:
149 ...
150 glRotatef( ... );
151 glMaterialfv( ... );
152 glBegin( GL_QUADS );
153 glVertex3f( ... );
154 glVertex3f( ... );
155 ...
156 glEnd();
157 ...
158 }
159
160 };
161 </pre>
162
163<p> If you need to trigger a repaint from places other than <a href="#paintGL">paintGL</a>()
164(a typical example is when using <a href="qtimer.html">timers</a> to
165animate scenes), you should call the widget's <a href="#updateGL">updateGL</a>() function.
166<p> Your widget's OpenGL rendering context is made current when
167paintGL(), <a href="#resizeGL">resizeGL</a>(), or <a href="#initializeGL">initializeGL</a>() is called. If you need to
168call the standard OpenGL API functions from other places (e.g. in
169your widget's constructor or in your own paint functions), you
170must call <a href="#makeCurrent">makeCurrent</a>() first.
171<p> QGLWidget provides functions for requesting a new display <a href="qglformat.html">format</a> and you can also create widgets with
172customized rendering <a href="qglcontext.html">contexts</a>.
173<p> You can also share OpenGL display lists between QGLWidgets (see
174the documentation of the QGLWidget constructors for details).
175<p> <h3> Overlays
176</h3>
177<a name="1"></a><p> The QGLWidget creates a GL overlay context in addition to the
178normal context if overlays are supported by the underlying system.
179<p> If you want to use overlays, you specify it in the <a href="qglformat.html">format</a>. (Note: Overlay must be requested in the format
180passed to the QGLWidget constructor.) Your GL widget should also
181implement some or all of these virtual methods:
182<p> <ul>
183<li> <a href="#paintOverlayGL">paintOverlayGL</a>()
184<li> <a href="#resizeOverlayGL">resizeOverlayGL</a>()
185<li> <a href="#initializeOverlayGL">initializeOverlayGL</a>()
186</ul>
187<p> These methods work in the same way as the normal <a href="#paintGL">paintGL</a>() etc.
188functions, except that they will be called when the overlay
189context is made current. You can explicitly make the overlay
190context current by using <a href="#makeOverlayCurrent">makeOverlayCurrent</a>(), and you can access
191the overlay context directly (e.g. to ask for its transparent
192color) by calling <a href="#overlayContext">overlayContext</a>().
193<p> On X servers in which the default visual is in an overlay plane,
194non-GL Qt windows can also be used for overlays. See the
195examples/opengl/overlay_x11 example program for details.
196<p> <sup>*</sup> OpenGL is a trademark of Silicon Graphics, Inc. in the
197United States and other countries.
198<p>See also <a href="graphics.html">Graphics Classes</a> and <a href="images.html">Image Processing Classes</a>.
199
200<hr><h2>Member Function Documentation</h2>
201<h3 class=fn><a name="QGLWidget"></a>QGLWidget::QGLWidget ( <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0, const&nbsp;<a href="qglwidget.html">QGLWidget</a>&nbsp;*&nbsp;shareWidget = 0, WFlags&nbsp;f = 0 )
202</h3>
203Constructs an OpenGL widget with a <em>parent</em> widget and a <em>name</em>.
204<p> The <a href="qglformat.html#defaultFormat">default format</a> is
205used. The widget will be <a href="#isValid">invalid</a> if the
206system has no <a href="qglformat.html#hasOpenGL">OpenGL support</a>.
207<p> The <em>parent</em>, <em>name</em> and <a href="qt.html#WidgetFlags">widget flag</a>, <em>f</em>, arguments are passed
208to the <a href="qwidget.html">QWidget</a> constructor.
209<p> If the <em>shareWidget</em> parameter points to a valid QGLWidget, this
210widget will share OpenGL display lists with <em>shareWidget</em>. If
211this widget and <em>shareWidget</em> have different <a href="#format">formats</a>, display list sharing may fail. You can check
212whether display list sharing succeeded by calling <a href="#isSharing">isSharing</a>().
213<p> The initialization of OpenGL rendering state, etc. should be done
214by overriding the <a href="#initializeGL">initializeGL</a>() function, rather than in the
215constructor of your QGLWidget subclass.
216<p> <p>See also <a href="qglformat.html#defaultFormat">QGLFormat::defaultFormat</a>().
217
218<h3 class=fn><a name="QGLWidget-2"></a>QGLWidget::QGLWidget ( <a href="qglcontext.html">QGLContext</a>&nbsp;*&nbsp;context, <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;parent, const&nbsp;char&nbsp;*&nbsp;name = 0, const&nbsp;<a href="qglwidget.html">QGLWidget</a>&nbsp;*&nbsp;shareWidget = 0, WFlags&nbsp;f = 0 )
219</h3>
220Constructs an OpenGL widget with parent <em>parent</em>, called <em>name</em>.
221<p> The <em>context</em> argument is a pointer to the <a href="qglcontext.html">QGLContext</a> that
222you wish to be bound to this widget. This allows you to pass in
223your own QGLContext sub-classes.
224<p> The widget will be <a href="#isValid">invalid</a> if the system
225has no <a href="qglformat.html#hasOpenGL">OpenGL support</a>.
226<p> The <em>parent</em>, <em>name</em> and <a href="qt.html#WidgetFlags">widget flag</a>, <em>f</em>, arguments are passed
227to the <a href="qwidget.html">QWidget</a> constructor.
228<p> If the <em>shareWidget</em> parameter points to a valid QGLWidget, this
229widget will share OpenGL display lists with <em>shareWidget</em>. If
230this widget and <em>shareWidget</em> have different <a href="#format">formats</a>, display list sharing may fail. You can check
231whether display list sharing succeeded by calling <a href="#isSharing">isSharing</a>().
232<p> The initialization of OpenGL rendering state, etc. should be done
233by overriding the <a href="#initializeGL">initializeGL</a>() function, rather than in the
234constructor of your QGLWidget subclass.
235<p> <p>See also <a href="qglformat.html#defaultFormat">QGLFormat::defaultFormat</a>() and <a href="#isValid">isValid</a>().
236
237<h3 class=fn><a name="QGLWidget-3"></a>QGLWidget::QGLWidget ( const&nbsp;<a href="qglformat.html">QGLFormat</a>&nbsp;&amp;&nbsp;format, <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0, const&nbsp;<a href="qglwidget.html">QGLWidget</a>&nbsp;*&nbsp;shareWidget = 0, WFlags&nbsp;f = 0 )
238</h3>
239Constructs an OpenGL widget with parent <em>parent</em>, called <em>name</em>.
240<p> The <em>format</em> argument specifies the desired <a href="qglformat.html">rendering options</a>. If the underlying OpenGL/Window system
241cannot satisfy all the features requested in <em>format</em>, the
242nearest subset of features will be used. After creation, the
243<a href="#format">format</a>() method will return the actual format obtained.
244<p> The widget will be <a href="#isValid">invalid</a> if the system
245has no <a href="qglformat.html#hasOpenGL">OpenGL support</a>.
246<p> The <em>parent</em>, <em>name</em> and <a href="qt.html#WidgetFlags">widget flag</a>, <em>f</em>, arguments are passed
247to the <a href="qwidget.html">QWidget</a> constructor.
248<p> If the <em>shareWidget</em> parameter points to a valid QGLWidget, this
249widget will share OpenGL display lists with <em>shareWidget</em>. If
250this widget and <em>shareWidget</em> have different <a href="#format">formats</a>, display list sharing may fail. You can check
251whether display list sharing succeeded by calling <a href="#isSharing">isSharing</a>().
252<p> The initialization of OpenGL rendering state, etc. should be done
253by overriding the <a href="#initializeGL">initializeGL</a>() function, rather than in the
254constructor of your QGLWidget subclass.
255<p> <p>See also <a href="qglformat.html#defaultFormat">QGLFormat::defaultFormat</a>() and <a href="#isValid">isValid</a>().
256
257<h3 class=fn><a name="~QGLWidget"></a>QGLWidget::~QGLWidget ()
258</h3>
259Destroys the widget.
260
261<h3 class=fn>bool <a name="autoBufferSwap"></a>QGLWidget::autoBufferSwap () const<tt> [protected]</tt>
262</h3>
263
264<p> Returns TRUE if the widget is doing automatic GL buffer swapping;
265otherwise returns FALSE.
266<p> <p>See also <a href="#setAutoBufferSwap">setAutoBufferSwap</a>().
267
268<h3 class=fn>const&nbsp;<a href="qglcolormap.html">QGLColormap</a>&nbsp;&amp; <a name="colormap"></a>QGLWidget::colormap () const
269</h3>
270
271<p> Returns the colormap for this widget.
272<p> Usually it is only top-level widgets that can have different
273colormaps installed. Asking for the colormap of a child widget
274will return the colormap for the child's top-level widget.
275<p> If no colormap has been set for this widget, the QColormap
276returned will be empty.
277<p> <p>See also <a href="#setColormap">setColormap</a>().
278
279<h3 class=fn>const&nbsp;<a href="qglcontext.html">QGLContext</a>&nbsp;* <a name="context"></a>QGLWidget::context () const
280</h3>
281
282<p> Returns the context of this widget.
283<p> It is possible that the context is not valid (see <a href="#isValid">isValid</a>()), for
284example, if the underlying hardware does not support the format
285attributes that were requested.
286
287<h3 class=fn><a href="qimage.html">QImage</a> <a name="convertToGLFormat"></a>QGLWidget::convertToGLFormat ( const&nbsp;<a href="qimage.html">QImage</a>&nbsp;&amp;&nbsp;img )<tt> [static]</tt>
288</h3>
289Converts the image <em>img</em> into the unnamed format expected by
290OpenGL functions such as glTexImage2D(). The returned image is not
291usable as a <a href="qimage.html">QImage</a>, but <a href="qimage.html#width">QImage::width</a>(), <a href="qimage.html#height">QImage::height</a>() and
292<a href="qimage.html#bits">QImage::bits</a>() may be used with OpenGL. The following few lines
293are from the texture example. Most of the code is irrelevant, so
294we just quote the relevant bits:
295<p>
296
297<pre> <a href="qimage.html">QImage</a> tex1, tex2, buf;
298 if ( !buf.load( "gllogo.bmp" ) ) { // Load first image from file
299</pre>
300<p> We create <em>tex1</em> (and another variable) for OpenGL, and load a real
301image into <em>buf</em>.
302<p> <pre> <a name="x2118"></a> tex1 = QGLWidget::<a href="#convertToGLFormat">convertToGLFormat</a>( buf ); // flipped 32bit RGBA
303</pre>
304<p> A few lines later, we convert <em>buf</em> into OpenGL format and store it
305in <em>tex1</em>.
306<p> <pre> <a name="x2121"></a><a name="x2120"></a> glTexImage2D( GL_TEXTURE_2D, 0, 3, tex1.<a href="qimage.html#width">width</a>(), tex1.<a href="qimage.html#height">height</a>(), 0,
307 <a name="x2119"></a> GL_RGBA, GL_UNSIGNED_BYTE, tex1.<a href="qimage.html#bits">bits</a>() );
308</pre>
309<p> Note the dimension restrictions for texture images as described in
310the glTexImage2D() documentation. The width must be 2^m + 2*border
311and the height 2^n + 2*border where m and n are integers and
312border is either 0 or 1.
313<p> Another function in the same example uses <em>tex1</em> with OpenGL.
314
315<p>Example: <a href="qglwidget.html#x2118">opengl/texture/gltexobj.cpp</a>.
316<h3 class=fn>void <a name="doneCurrent"></a>QGLWidget::doneCurrent ()
317</h3>
318
319<p> Makes no GL context the current context. Normally, you do not need
320to call this function; <a href="qglcontext.html">QGLContext</a> calls it as necessary. However,
321it may be useful in multithreaded environments.
322
323<h3 class=fn>bool <a name="doubleBuffer"></a>QGLWidget::doubleBuffer () const
324</h3>
325
326<p> Returns TRUE if the contained GL rendering context has double
327buffering; otherwise returns FALSE.
328<p> <p>See also <a href="qglformat.html#doubleBuffer">QGLFormat::doubleBuffer</a>().
329
330<h3 class=fn><a href="qglformat.html">QGLFormat</a> <a name="format"></a>QGLWidget::format () const
331</h3>
332
333<p> Returns the format of the contained GL rendering context.
334
335<h3 class=fn>void <a name="glDraw"></a>QGLWidget::glDraw ()<tt> [virtual protected]</tt>
336</h3>
337Executes the virtual function <a href="#paintGL">paintGL</a>().
338<p> The widget's rendering context will become the current context and
339<a href="#initializeGL">initializeGL</a>() will be called if it hasn't already been called.
340
341<h3 class=fn>void <a name="glInit"></a>QGLWidget::glInit ()<tt> [virtual protected]</tt>
342</h3>
343Initializes OpenGL for this widget's context. Calls the virtual
344function <a href="#initializeGL">initializeGL</a>().
345
346<h3 class=fn><a href="qimage.html">QImage</a> <a name="grabFrameBuffer"></a>QGLWidget::grabFrameBuffer ( bool&nbsp;withAlpha = FALSE )<tt> [virtual]</tt>
347</h3>
348Returns an image of the frame buffer. If <em>withAlpha</em> is TRUE the
349alpha channel is included.
350<p> Depending on your hardware, you can explicitly select which color
351buffer to grab with a glReadBuffer() call before calling this
352function.
353
354<h3 class=fn>void <a name="initializeGL"></a>QGLWidget::initializeGL ()<tt> [virtual protected]</tt>
355</h3>
356This virtual function is called once before the first call to
357<a href="#paintGL">paintGL</a>() or <a href="#resizeGL">resizeGL</a>(), and then once whenever the widget has
358been assigned a new <a href="qglcontext.html">QGLContext</a>. Reimplement it in a subclass.
359<p> This function should set up any required OpenGL context rendering
360flags, defining display lists, etc.
361<p> There is no need to call <a href="#makeCurrent">makeCurrent</a>() because this has already
362been done when this function is called.
363
364<h3 class=fn>void <a name="initializeOverlayGL"></a>QGLWidget::initializeOverlayGL ()<tt> [virtual protected]</tt>
365</h3>
366This virtual function is used in the same manner as <a href="#initializeGL">initializeGL</a>()
367except that it operates on the widget's overlay context instead of
368the widget's main context. This means that <a href="#initializeOverlayGL">initializeOverlayGL</a>()
369is called once before the first call to <a href="#paintOverlayGL">paintOverlayGL</a>() or
370<a href="#resizeOverlayGL">resizeOverlayGL</a>(). Reimplement it in a subclass.
371<p> This function should set up any required OpenGL context rendering
372flags, defining display lists, etc. for the overlay context.
373<p> There is no need to call <a href="#makeOverlayCurrent">makeOverlayCurrent</a>() because this has
374already been done when this function is called.
375
376<h3 class=fn>bool <a name="isSharing"></a>QGLWidget::isSharing () const
377</h3>
378
379<p> Returns TRUE if display list sharing with another QGLWidget was
380requested in the constructor, and the GL system was able to
381provide it; otherwise returns FALSE. The GL system may fail to
382provide display list sharing if the two QGLWidgets use different
383formats.
384<p> <p>See also <a href="#format">format</a>().
385
386<h3 class=fn>bool <a name="isValid"></a>QGLWidget::isValid () const
387</h3>
388
389<p> Returns TRUE if the widget has a valid GL rendering context;
390otherwise returns FALSE. A widget will be invalid if the system
391has no <a href="qglformat.html#hasOpenGL">OpenGL support</a>.
392
393<h3 class=fn>void <a name="makeCurrent"></a>QGLWidget::makeCurrent ()<tt> [virtual]</tt>
394</h3>
395
396<p> Makes this widget the current widget for OpenGL operations, i.e.
397makes the widget's rendering context the current OpenGL rendering
398context.
399
400<h3 class=fn>void <a name="makeOverlayCurrent"></a>QGLWidget::makeOverlayCurrent ()<tt> [virtual]</tt>
401</h3>
402
403<p> Makes the overlay context of this widget current. Use this if you
404need to issue OpenGL commands to the overlay context outside of
405<a href="#initializeOverlayGL">initializeOverlayGL</a>(), <a href="#resizeOverlayGL">resizeOverlayGL</a>(), and <a href="#paintOverlayGL">paintOverlayGL</a>().
406<p> Does nothing if this widget has no overlay.
407<p> <p>See also <a href="#makeCurrent">makeCurrent</a>().
408
409<h3 class=fn>const&nbsp;<a href="qglcontext.html">QGLContext</a>&nbsp;* <a name="overlayContext"></a>QGLWidget::overlayContext () const
410</h3>
411
412<p> Returns the overlay context of this widget, or 0 if this widget
413has no overlay.
414<p> <p>See also <a href="#context">context</a>().
415
416<h3 class=fn>void <a name="paintEvent"></a>QGLWidget::paintEvent ( <a href="qpaintevent.html">QPaintEvent</a>&nbsp;* )<tt> [virtual protected]</tt>
417</h3>
418Handles paint events. Will cause the virtual <a href="#paintGL">paintGL</a>() function to
419be called.
420<p> The widget's rendering context will become the current context and
421<a href="#initializeGL">initializeGL</a>() will be called if it hasn't already been called.
422
423<p>Reimplemented from <a href="qwidget.html#paintEvent">QWidget</a>.
424<h3 class=fn>void <a name="paintGL"></a>QGLWidget::paintGL ()<tt> [virtual protected]</tt>
425</h3>
426This virtual function is called whenever the widget needs to be
427painted. Reimplement it in a subclass.
428<p> There is no need to call <a href="#makeCurrent">makeCurrent</a>() because this has already
429been done when this function is called.
430
431<h3 class=fn>void <a name="paintOverlayGL"></a>QGLWidget::paintOverlayGL ()<tt> [virtual protected]</tt>
432</h3>
433This virtual function is used in the same manner as <a href="#paintGL">paintGL</a>()
434except that it operates on the widget's overlay context instead of
435the widget's main context. This means that <a href="#paintOverlayGL">paintOverlayGL</a>() is
436called whenever the widget's overlay needs to be painted.
437Reimplement it in a subclass.
438<p> There is no need to call <a href="#makeOverlayCurrent">makeOverlayCurrent</a>() because this has
439already been done when this function is called.
440
441<h3 class=fn>void <a name="qglClearColor"></a>QGLWidget::qglClearColor ( const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;c ) const
442</h3>
443Convenience function for specifying the clearing color to OpenGL.
444Calls glClearColor (in RGBA mode) or glClearIndex (in color-index
445mode) with the color <em>c</em>. Applies to the current GL context.
446<p> <p>See also <a href="#qglColor">qglColor</a>(), <a href="qglcontext.html#currentContext">QGLContext::currentContext</a>(), and <a href="qcolor.html">QColor</a>.
447
448<h3 class=fn>void <a name="qglColor"></a>QGLWidget::qglColor ( const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;c ) const
449</h3>
450Convenience function for specifying a drawing color to OpenGL.
451Calls glColor3 (in RGBA mode) or glIndex (in color-index mode)
452with the color <em>c</em>. Applies to the current GL context.
453<p> <p>See also <a href="#qglClearColor">qglClearColor</a>(), <a href="qglcontext.html#currentContext">QGLContext::currentContext</a>(), and <a href="qcolor.html">QColor</a>.
454
455<h3 class=fn><a href="qpixmap.html">QPixmap</a> <a name="renderPixmap"></a>QGLWidget::renderPixmap ( int&nbsp;w = 0, int&nbsp;h = 0, bool&nbsp;useContext = FALSE )<tt> [virtual]</tt>
456</h3>
457Renders the current scene on a pixmap and returns the pixmap.
458<p> You can use this method on both visible and invisible QGLWidgets.
459<p> This method will create a pixmap and a temporary <a href="qglcontext.html">QGLContext</a> to
460render on the pixmap. It will then call <a href="#initializeGL">initializeGL</a>(),
461<a href="#resizeGL">resizeGL</a>(), and <a href="#paintGL">paintGL</a>() on this context. Finally, the widget's
462original GL context is restored.
463<p> The size of the pixmap will be <em>w</em> pixels wide and <em>h</em> pixels
464high unless one of these parameters is 0 (the default), in which
465case the pixmap will have the same size as the widget.
466<p> If <em>useContext</em> is TRUE, this method will try to be more
467efficient by using the existing GL context to render the pixmap.
468The default is FALSE. Only use TRUE if you understand the risks.
469<p> Overlays are not rendered onto the pixmap.
470<p> If the GL rendering context and the desktop have different bit
471depths, the result will most likely look surprising.
472<p> Note that the creation of display lists, modifications of the view
473frustum etc. should be done from within initializeGL(). If this is
474not done, the temporary QGLContext will not be initialized
475properly, and the rendered pixmap may be incomplete/corrupted.
476
477<h3 class=fn>void <a name="renderText"></a>QGLWidget::renderText ( int&nbsp;x, int&nbsp;y, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;str, const&nbsp;<a href="qfont.html">QFont</a>&nbsp;&amp;&nbsp;fnt = QFont ( ), int&nbsp;listBase = 2000 )
478</h3>
479Renders the string <em>str</em> into the GL context of this widget.
480<p> <em>x</em> and <em>y</em> are specified in window coordinates, with the origin
481in the upper left-hand corner of the window. If <em>fnt</em> is not
482specified, the currently set application font will be used to
483render the string. To change the color of the rendered text you can
484use the glColor() call (or the <a href="#qglColor">qglColor</a>() convenience function),
485just before the <a href="#renderText">renderText</a>() call. Note that if you have
486GL_LIGHTING enabled, the string will not appear in the color you
487want. You should therefore switch lighting off before using
488renderText().
489<p> <em>listBase</em> specifies the index of the first display list that is
490generated by this function. The default value is 2000. 256 display
491lists will be generated, one for each of the first 256 characters
492in the font that is used to render the string. If several fonts are
493used in the same widget, the display lists for these fonts will
494follow the last generated list. You would normally not have to
495change this value unless you are using lists in the same range. The
496lists are deleted when the widget is destroyed.
497<p> Note: This function only works reliably with ASCII strings.
498
499<h3 class=fn>void <a name="renderText-2"></a>QGLWidget::renderText ( double&nbsp;x, double&nbsp;y, double&nbsp;z, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;str, const&nbsp;<a href="qfont.html">QFont</a>&nbsp;&amp;&nbsp;fnt = QFont ( ), int&nbsp;listBase = 2000 )
500</h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
501<p> <em>x</em>, <em>y</em> and <em>z</em> are specified in scene or object coordinates
502relative to the currently set projection and model matrices. This
503can be useful if you want to annotate models with text labels and
504have the labels move with the model as it is rotated etc.
505
506<h3 class=fn>void <a name="resizeEvent"></a>QGLWidget::resizeEvent ( <a href="qresizeevent.html">QResizeEvent</a>&nbsp;* )<tt> [virtual protected]</tt>
507</h3>
508
509<p> Handles resize events. Calls the virtual function <a href="#resizeGL">resizeGL</a>().
510
511<p>Reimplemented from <a href="qwidget.html#resizeEvent">QWidget</a>.
512<h3 class=fn>void <a name="resizeGL"></a>QGLWidget::resizeGL ( int&nbsp;width, int&nbsp;height )<tt> [virtual protected]</tt>
513</h3>
514
515<p> This virtual function is called whenever the widget has been
516resized. The new size is passed in <em>width</em> and <em>height</em>.
517Reimplement it in a subclass.
518<p> There is no need to call <a href="#makeCurrent">makeCurrent</a>() because this has already
519been done when this function is called.
520
521<h3 class=fn>void <a name="resizeOverlayGL"></a>QGLWidget::resizeOverlayGL ( int&nbsp;width, int&nbsp;height )<tt> [virtual protected]</tt>
522</h3>
523
524<p> This virtual function is used in the same manner as <a href="#paintGL">paintGL</a>()
525except that it operates on the widget's overlay context instead of
526the widget's main context. This means that <a href="#resizeOverlayGL">resizeOverlayGL</a>() is
527called whenever the widget has been resized. The new size is
528passed in <em>width</em> and <em>height</em>. Reimplement it in a subclass.
529<p> There is no need to call <a href="#makeOverlayCurrent">makeOverlayCurrent</a>() because this has
530already been done when this function is called.
531
532<h3 class=fn>void <a name="setAutoBufferSwap"></a>QGLWidget::setAutoBufferSwap ( bool&nbsp;on )<tt> [protected]</tt>
533</h3>
534
535<p> If <em>on</em> is TRUE automatic GL buffer swapping is switched on;
536otherwise it is switched off.
537<p> If <em>on</em> is TRUE and the widget is using a double-buffered format,
538the background and foreground GL buffers will automatically be
539swapped after each <a href="#paintGL">paintGL</a>() call.
540<p> The buffer auto-swapping is on by default.
541<p> <p>See also <a href="#autoBufferSwap">autoBufferSwap</a>(), <a href="#doubleBuffer">doubleBuffer</a>(), and <a href="#swapBuffers">swapBuffers</a>().
542
543<h3 class=fn>void <a name="setColormap"></a>QGLWidget::setColormap ( const&nbsp;<a href="qglcolormap.html">QGLColormap</a>&nbsp;&amp;&nbsp;cmap )
544</h3>
545
546<p> Set the colormap for this widget to <em>cmap</em>. Usually it is only
547top-level widgets that can have colormaps installed.
548<p> <p>See also <a href="#colormap">colormap</a>().
549
550<h3 class=fn>void <a name="swapBuffers"></a>QGLWidget::swapBuffers ()<tt> [virtual]</tt>
551</h3>
552
553<p> Swaps the screen contents with an off-screen buffer. This only
554works if the widget's format specifies double buffer mode.
555<p> Normally, there is no need to explicitly call this function
556because it is done automatically after each widget repaint, i.e.
557each time after <a href="#paintGL">paintGL</a>() has been executed.
558<p> <p>See also <a href="#doubleBuffer">doubleBuffer</a>(), <a href="#setAutoBufferSwap">setAutoBufferSwap</a>(), and <a href="qglformat.html#setDoubleBuffer">QGLFormat::setDoubleBuffer</a>().
559
560<h3 class=fn>void <a name="updateGL"></a>QGLWidget::updateGL ()<tt> [virtual slot]</tt>
561</h3>
562
563<p> Updates the widget by calling <a href="#glDraw">glDraw</a>().
564
565<h3 class=fn>void <a name="updateOverlayGL"></a>QGLWidget::updateOverlayGL ()<tt> [virtual slot]</tt>
566</h3>
567
568<p> Updates the widget's overlay (if any). Will cause the virtual
569function <a href="#paintOverlayGL">paintOverlayGL</a>() to be executed.
570<p> The widget's rendering context will become the current context and
571<a href="#initializeGL">initializeGL</a>() will be called if it hasn't already been called.
572
573<!-- eof -->
574<hr><p>
575This file is part of the <a href="index.html">Qt toolkit</a>.
576Copyright &copy; 1995-2007
577<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
578<table width=100% cellspacing=0 border=0><tr>
579<td>Copyright &copy; 2007
580<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
581<td align=right><div align=right>Qt 3.3.8</div>
582</table></div></address></body>
583</html>
Note: See TracBrowser for help on using the repository browser.