[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"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { 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 Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main 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 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 <<a href="qgl-h.html">qgl.h</a>></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 * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags f = 0 )</li>
|
---|
| 42 | <li class=fn><a href="#QGLWidget-2"><b>QGLWidget</b></a> ( QGLContext * context, QWidget * parent, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags f = 0 )</li>
|
---|
| 43 | <li class=fn><a href="#QGLWidget-3"><b>QGLWidget</b></a> ( const QGLFormat & format, QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags 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 QColor & c ) const</li>
|
---|
| 46 | <li class=fn>void <a href="#qglClearColor"><b>qglClearColor</b></a> ( const QColor & 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 w = 0, int h = 0, bool useContext = FALSE )</li>
|
---|
| 56 | <li class=fn>virtual QImage <a href="#grabFrameBuffer"><b>grabFrameBuffer</b></a> ( bool 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 & <a href="#colormap"><b>colormap</b></a> () const</li>
|
---|
| 60 | <li class=fn>void <a href="#setColormap"><b>setColormap</b></a> ( const QGLColormap & cmap )</li>
|
---|
| 61 | <li class=fn>void <a href="#renderText"><b>renderText</b></a> ( int x, int y, const QString & str, const QFont & fnt = QFont ( ), int listBase = 2000 )</li>
|
---|
| 62 | <li class=fn>void <a href="#renderText-2"><b>renderText</b></a> ( double x, double y, double z, const QString & str, const QFont & fnt = QFont ( ), int 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 QImage & 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 width, int 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 width, int 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 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 |
|
---|
| 91 | The 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>
|
---|
| 98 | graphics integrated into a Qt application. It is very simple to
|
---|
| 99 | use. 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
|
---|
| 101 | using <a href="qpainter.html">QPainter</a> etc. you use the standard OpenGL rendering
|
---|
| 102 | commands.
|
---|
| 103 | <p> QGLWidget provides three convenient virtual functions that you can
|
---|
| 104 | reimplement 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
|
---|
| 107 | needs to be updated.
|
---|
| 108 | <li> <a href="#resizeGL">resizeGL</a>() - Sets up the OpenGL viewport, projection, etc. Gets
|
---|
| 109 | called whenever the the widget has been resized (and also when it
|
---|
| 110 | is shown for the first time because all newly created widgets get a
|
---|
| 111 | resize event automatically).
|
---|
| 112 | <li> <a href="#initializeGL">initializeGL</a>() - Sets up the OpenGL rendering context, defines display
|
---|
| 113 | lists, etc. Gets called once before the first time resizeGL() or
|
---|
| 114 | paintGL() 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
|
---|
| 165 | animate 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
|
---|
| 167 | paintGL(), <a href="#resizeGL">resizeGL</a>(), or <a href="#initializeGL">initializeGL</a>() is called. If you need to
|
---|
| 168 | call the standard OpenGL API functions from other places (e.g. in
|
---|
| 169 | your widget's constructor or in your own paint functions), you
|
---|
| 170 | must 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
|
---|
| 172 | customized rendering <a href="qglcontext.html">contexts</a>.
|
---|
| 173 | <p> You can also share OpenGL display lists between QGLWidgets (see
|
---|
| 174 | the 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
|
---|
| 178 | normal 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
|
---|
| 180 | passed to the QGLWidget constructor.) Your GL widget should also
|
---|
| 181 | implement 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.
|
---|
| 188 | functions, except that they will be called when the overlay
|
---|
| 189 | context is made current. You can explicitly make the overlay
|
---|
| 190 | context current by using <a href="#makeOverlayCurrent">makeOverlayCurrent</a>(), and you can access
|
---|
| 191 | the overlay context directly (e.g. to ask for its transparent
|
---|
| 192 | color) by calling <a href="#overlayContext">overlayContext</a>().
|
---|
| 193 | <p> On X servers in which the default visual is in an overlay plane,
|
---|
| 194 | non-GL Qt windows can also be used for overlays. See the
|
---|
| 195 | examples/opengl/overlay_x11 example program for details.
|
---|
| 196 | <p> <sup>*</sup> OpenGL is a trademark of Silicon Graphics, Inc. in the
|
---|
| 197 | United 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> * parent = 0, const char * name = 0, const <a href="qglwidget.html">QGLWidget</a> * shareWidget = 0, WFlags f = 0 )
|
---|
| 202 | </h3>
|
---|
| 203 | Constructs 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
|
---|
| 205 | used. The widget will be <a href="#isValid">invalid</a> if the
|
---|
| 206 | system 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
|
---|
| 208 | to the <a href="qwidget.html">QWidget</a> constructor.
|
---|
| 209 | <p> If the <em>shareWidget</em> parameter points to a valid QGLWidget, this
|
---|
| 210 | widget will share OpenGL display lists with <em>shareWidget</em>. If
|
---|
| 211 | this widget and <em>shareWidget</em> have different <a href="#format">formats</a>, display list sharing may fail. You can check
|
---|
| 212 | whether display list sharing succeeded by calling <a href="#isSharing">isSharing</a>().
|
---|
| 213 | <p> The initialization of OpenGL rendering state, etc. should be done
|
---|
| 214 | by overriding the <a href="#initializeGL">initializeGL</a>() function, rather than in the
|
---|
| 215 | constructor 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> * context, <a href="qwidget.html">QWidget</a> * parent, const char * name = 0, const <a href="qglwidget.html">QGLWidget</a> * shareWidget = 0, WFlags f = 0 )
|
---|
| 219 | </h3>
|
---|
| 220 | Constructs 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
|
---|
| 222 | you wish to be bound to this widget. This allows you to pass in
|
---|
| 223 | your own QGLContext sub-classes.
|
---|
| 224 | <p> The widget will be <a href="#isValid">invalid</a> if the system
|
---|
| 225 | has 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
|
---|
| 227 | to the <a href="qwidget.html">QWidget</a> constructor.
|
---|
| 228 | <p> If the <em>shareWidget</em> parameter points to a valid QGLWidget, this
|
---|
| 229 | widget will share OpenGL display lists with <em>shareWidget</em>. If
|
---|
| 230 | this widget and <em>shareWidget</em> have different <a href="#format">formats</a>, display list sharing may fail. You can check
|
---|
| 231 | whether display list sharing succeeded by calling <a href="#isSharing">isSharing</a>().
|
---|
| 232 | <p> The initialization of OpenGL rendering state, etc. should be done
|
---|
| 233 | by overriding the <a href="#initializeGL">initializeGL</a>() function, rather than in the
|
---|
| 234 | constructor 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 <a href="qglformat.html">QGLFormat</a> & format, <a href="qwidget.html">QWidget</a> * parent = 0, const char * name = 0, const <a href="qglwidget.html">QGLWidget</a> * shareWidget = 0, WFlags f = 0 )
|
---|
| 238 | </h3>
|
---|
| 239 | Constructs 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
|
---|
| 241 | cannot satisfy all the features requested in <em>format</em>, the
|
---|
| 242 | nearest 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
|
---|
| 245 | has 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
|
---|
| 247 | to the <a href="qwidget.html">QWidget</a> constructor.
|
---|
| 248 | <p> If the <em>shareWidget</em> parameter points to a valid QGLWidget, this
|
---|
| 249 | widget will share OpenGL display lists with <em>shareWidget</em>. If
|
---|
| 250 | this widget and <em>shareWidget</em> have different <a href="#format">formats</a>, display list sharing may fail. You can check
|
---|
| 251 | whether display list sharing succeeded by calling <a href="#isSharing">isSharing</a>().
|
---|
| 252 | <p> The initialization of OpenGL rendering state, etc. should be done
|
---|
| 253 | by overriding the <a href="#initializeGL">initializeGL</a>() function, rather than in the
|
---|
| 254 | constructor 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>
|
---|
| 259 | Destroys 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;
|
---|
| 265 | otherwise returns FALSE.
|
---|
| 266 | <p> <p>See also <a href="#setAutoBufferSwap">setAutoBufferSwap</a>().
|
---|
| 267 |
|
---|
| 268 | <h3 class=fn>const <a href="qglcolormap.html">QGLColormap</a> & <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
|
---|
| 273 | colormaps installed. Asking for the colormap of a child widget
|
---|
| 274 | will return the colormap for the child's top-level widget.
|
---|
| 275 | <p> If no colormap has been set for this widget, the QColormap
|
---|
| 276 | returned will be empty.
|
---|
| 277 | <p> <p>See also <a href="#setColormap">setColormap</a>().
|
---|
| 278 |
|
---|
| 279 | <h3 class=fn>const <a href="qglcontext.html">QGLContext</a> * <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
|
---|
| 284 | example, if the underlying hardware does not support the format
|
---|
| 285 | attributes that were requested.
|
---|
| 286 |
|
---|
| 287 | <h3 class=fn><a href="qimage.html">QImage</a> <a name="convertToGLFormat"></a>QGLWidget::convertToGLFormat ( const <a href="qimage.html">QImage</a> & img )<tt> [static]</tt>
|
---|
| 288 | </h3>
|
---|
| 289 | Converts the image <em>img</em> into the unnamed format expected by
|
---|
| 290 | OpenGL functions such as glTexImage2D(). The returned image is not
|
---|
| 291 | usable 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
|
---|
| 293 | are from the texture example. Most of the code is irrelevant, so
|
---|
| 294 | we 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
|
---|
| 301 | image 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
|
---|
| 305 | in <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
|
---|
| 310 | the glTexImage2D() documentation. The width must be 2^m + 2*border
|
---|
| 311 | and the height 2^n + 2*border where m and n are integers and
|
---|
| 312 | border 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
|
---|
| 320 | to call this function; <a href="qglcontext.html">QGLContext</a> calls it as necessary. However,
|
---|
| 321 | it 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
|
---|
| 327 | buffering; 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>
|
---|
| 337 | Executes 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>
|
---|
| 343 | Initializes OpenGL for this widget's context. Calls the virtual
|
---|
| 344 | function <a href="#initializeGL">initializeGL</a>().
|
---|
| 345 |
|
---|
| 346 | <h3 class=fn><a href="qimage.html">QImage</a> <a name="grabFrameBuffer"></a>QGLWidget::grabFrameBuffer ( bool withAlpha = FALSE )<tt> [virtual]</tt>
|
---|
| 347 | </h3>
|
---|
| 348 | Returns an image of the frame buffer. If <em>withAlpha</em> is TRUE the
|
---|
| 349 | alpha channel is included.
|
---|
| 350 | <p> Depending on your hardware, you can explicitly select which color
|
---|
| 351 | buffer to grab with a glReadBuffer() call before calling this
|
---|
| 352 | function.
|
---|
| 353 |
|
---|
| 354 | <h3 class=fn>void <a name="initializeGL"></a>QGLWidget::initializeGL ()<tt> [virtual protected]</tt>
|
---|
| 355 | </h3>
|
---|
| 356 | This 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
|
---|
| 358 | been 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
|
---|
| 360 | flags, defining display lists, etc.
|
---|
| 361 | <p> There is no need to call <a href="#makeCurrent">makeCurrent</a>() because this has already
|
---|
| 362 | been done when this function is called.
|
---|
| 363 |
|
---|
| 364 | <h3 class=fn>void <a name="initializeOverlayGL"></a>QGLWidget::initializeOverlayGL ()<tt> [virtual protected]</tt>
|
---|
| 365 | </h3>
|
---|
| 366 | This virtual function is used in the same manner as <a href="#initializeGL">initializeGL</a>()
|
---|
| 367 | except that it operates on the widget's overlay context instead of
|
---|
| 368 | the widget's main context. This means that <a href="#initializeOverlayGL">initializeOverlayGL</a>()
|
---|
| 369 | is 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
|
---|
| 372 | flags, defining display lists, etc. for the overlay context.
|
---|
| 373 | <p> There is no need to call <a href="#makeOverlayCurrent">makeOverlayCurrent</a>() because this has
|
---|
| 374 | already 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
|
---|
| 380 | requested in the constructor, and the GL system was able to
|
---|
| 381 | provide it; otherwise returns FALSE. The GL system may fail to
|
---|
| 382 | provide display list sharing if the two QGLWidgets use different
|
---|
| 383 | formats.
|
---|
| 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;
|
---|
| 390 | otherwise returns FALSE. A widget will be invalid if the system
|
---|
| 391 | has 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.
|
---|
| 397 | makes the widget's rendering context the current OpenGL rendering
|
---|
| 398 | context.
|
---|
| 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
|
---|
| 404 | need 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 <a href="qglcontext.html">QGLContext</a> * <a name="overlayContext"></a>QGLWidget::overlayContext () const
|
---|
| 410 | </h3>
|
---|
| 411 |
|
---|
| 412 | <p> Returns the overlay context of this widget, or 0 if this widget
|
---|
| 413 | has 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> * )<tt> [virtual protected]</tt>
|
---|
| 417 | </h3>
|
---|
| 418 | Handles paint events. Will cause the virtual <a href="#paintGL">paintGL</a>() function to
|
---|
| 419 | be 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>
|
---|
| 426 | This virtual function is called whenever the widget needs to be
|
---|
| 427 | painted. Reimplement it in a subclass.
|
---|
| 428 | <p> There is no need to call <a href="#makeCurrent">makeCurrent</a>() because this has already
|
---|
| 429 | been done when this function is called.
|
---|
| 430 |
|
---|
| 431 | <h3 class=fn>void <a name="paintOverlayGL"></a>QGLWidget::paintOverlayGL ()<tt> [virtual protected]</tt>
|
---|
| 432 | </h3>
|
---|
| 433 | This virtual function is used in the same manner as <a href="#paintGL">paintGL</a>()
|
---|
| 434 | except that it operates on the widget's overlay context instead of
|
---|
| 435 | the widget's main context. This means that <a href="#paintOverlayGL">paintOverlayGL</a>() is
|
---|
| 436 | called whenever the widget's overlay needs to be painted.
|
---|
| 437 | Reimplement it in a subclass.
|
---|
| 438 | <p> There is no need to call <a href="#makeOverlayCurrent">makeOverlayCurrent</a>() because this has
|
---|
| 439 | already been done when this function is called.
|
---|
| 440 |
|
---|
| 441 | <h3 class=fn>void <a name="qglClearColor"></a>QGLWidget::qglClearColor ( const <a href="qcolor.html">QColor</a> & c ) const
|
---|
| 442 | </h3>
|
---|
| 443 | Convenience function for specifying the clearing color to OpenGL.
|
---|
| 444 | Calls glClearColor (in RGBA mode) or glClearIndex (in color-index
|
---|
| 445 | mode) 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 <a href="qcolor.html">QColor</a> & c ) const
|
---|
| 449 | </h3>
|
---|
| 450 | Convenience function for specifying a drawing color to OpenGL.
|
---|
| 451 | Calls glColor3 (in RGBA mode) or glIndex (in color-index mode)
|
---|
| 452 | with 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 w = 0, int h = 0, bool useContext = FALSE )<tt> [virtual]</tt>
|
---|
| 456 | </h3>
|
---|
| 457 | Renders 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
|
---|
| 460 | render 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
|
---|
| 462 | original GL context is restored.
|
---|
| 463 | <p> The size of the pixmap will be <em>w</em> pixels wide and <em>h</em> pixels
|
---|
| 464 | high unless one of these parameters is 0 (the default), in which
|
---|
| 465 | case 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
|
---|
| 467 | efficient by using the existing GL context to render the pixmap.
|
---|
| 468 | The 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
|
---|
| 471 | depths, the result will most likely look surprising.
|
---|
| 472 | <p> Note that the creation of display lists, modifications of the view
|
---|
| 473 | frustum etc. should be done from within initializeGL(). If this is
|
---|
| 474 | not done, the temporary QGLContext will not be initialized
|
---|
| 475 | properly, and the rendered pixmap may be incomplete/corrupted.
|
---|
| 476 |
|
---|
| 477 | <h3 class=fn>void <a name="renderText"></a>QGLWidget::renderText ( int x, int y, const <a href="qstring.html">QString</a> & str, const <a href="qfont.html">QFont</a> & fnt = QFont ( ), int listBase = 2000 )
|
---|
| 478 | </h3>
|
---|
| 479 | Renders 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
|
---|
| 481 | in the upper left-hand corner of the window. If <em>fnt</em> is not
|
---|
| 482 | specified, the currently set application font will be used to
|
---|
| 483 | render the string. To change the color of the rendered text you can
|
---|
| 484 | use the glColor() call (or the <a href="#qglColor">qglColor</a>() convenience function),
|
---|
| 485 | just before the <a href="#renderText">renderText</a>() call. Note that if you have
|
---|
| 486 | GL_LIGHTING enabled, the string will not appear in the color you
|
---|
| 487 | want. You should therefore switch lighting off before using
|
---|
| 488 | renderText().
|
---|
| 489 | <p> <em>listBase</em> specifies the index of the first display list that is
|
---|
| 490 | generated by this function. The default value is 2000. 256 display
|
---|
| 491 | lists will be generated, one for each of the first 256 characters
|
---|
| 492 | in the font that is used to render the string. If several fonts are
|
---|
| 493 | used in the same widget, the display lists for these fonts will
|
---|
| 494 | follow the last generated list. You would normally not have to
|
---|
| 495 | change this value unless you are using lists in the same range. The
|
---|
| 496 | lists 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 x, double y, double z, const <a href="qstring.html">QString</a> & str, const <a href="qfont.html">QFont</a> & fnt = QFont ( ), int 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
|
---|
| 502 | relative to the currently set projection and model matrices. This
|
---|
| 503 | can be useful if you want to annotate models with text labels and
|
---|
| 504 | have 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> * )<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 width, int height )<tt> [virtual protected]</tt>
|
---|
| 513 | </h3>
|
---|
| 514 |
|
---|
| 515 | <p> This virtual function is called whenever the widget has been
|
---|
| 516 | resized. The new size is passed in <em>width</em> and <em>height</em>.
|
---|
| 517 | Reimplement it in a subclass.
|
---|
| 518 | <p> There is no need to call <a href="#makeCurrent">makeCurrent</a>() because this has already
|
---|
| 519 | been done when this function is called.
|
---|
| 520 |
|
---|
| 521 | <h3 class=fn>void <a name="resizeOverlayGL"></a>QGLWidget::resizeOverlayGL ( int width, int 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>()
|
---|
| 525 | except that it operates on the widget's overlay context instead of
|
---|
| 526 | the widget's main context. This means that <a href="#resizeOverlayGL">resizeOverlayGL</a>() is
|
---|
| 527 | called whenever the widget has been resized. The new size is
|
---|
| 528 | passed 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
|
---|
| 530 | already been done when this function is called.
|
---|
| 531 |
|
---|
| 532 | <h3 class=fn>void <a name="setAutoBufferSwap"></a>QGLWidget::setAutoBufferSwap ( bool on )<tt> [protected]</tt>
|
---|
| 533 | </h3>
|
---|
| 534 |
|
---|
| 535 | <p> If <em>on</em> is TRUE automatic GL buffer swapping is switched on;
|
---|
| 536 | otherwise it is switched off.
|
---|
| 537 | <p> If <em>on</em> is TRUE and the widget is using a double-buffered format,
|
---|
| 538 | the background and foreground GL buffers will automatically be
|
---|
| 539 | swapped 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 <a href="qglcolormap.html">QGLColormap</a> & cmap )
|
---|
| 544 | </h3>
|
---|
| 545 |
|
---|
| 546 | <p> Set the colormap for this widget to <em>cmap</em>. Usually it is only
|
---|
| 547 | top-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
|
---|
| 554 | works if the widget's format specifies double buffer mode.
|
---|
| 555 | <p> Normally, there is no need to explicitly call this function
|
---|
| 556 | because it is done automatically after each widget repaint, i.e.
|
---|
| 557 | each 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
|
---|
| 569 | function <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>
|
---|
| 575 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
| 576 | Copyright © 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 © 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>
|
---|