source: trunk/doc/html/qgl-h.html@ 208

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

reference documentation added

File size: 15.1 KB
Line 
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/include/qgl.h:1 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>qgl.h Include File</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>qgl.h</h1>
33
34<p>This is the verbatim text of the qgl.h include file. It is provided only for illustration; the copyright remains with Trolltech.
35<hr>
36<pre>
37/****************************************************************************
38** $Id: qgl-h.html 2051 2007-02-21 10:04:20Z chehrlic $
39**
40** Definition of OpenGL classes for Qt
41**
42** Created : 970112
43**
44** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
45**
46** This file is part of the opengl module of the Qt GUI Toolkit.
47**
48** This file may be distributed under the terms of the Q Public License
49** as defined by Trolltech ASA of Norway and appearing in the file
50** LICENSE.QPL included in the packaging of this file.
51**
52** This file may be distributed and/or modified under the terms of the
53** GNU General Public License version 2 as published by the Free Software
54** Foundation and appearing in the file LICENSE.GPL included in the
55** packaging of this file.
56**
57** Licensees holding valid Qt Enterprise Edition licenses may use this
58** file in accordance with the Qt Commercial License Agreement provided
59** with the Software.
60**
61** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
62** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
63**
64** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
65** information about Qt Commercial License Agreements.
66** See http://www.trolltech.com/qpl/ for QPL licensing information.
67** See http://www.trolltech.com/gpl/ for GPL licensing information.
68**
69** Contact info@trolltech.com if any conditions of this licensing are
70** not clear to you.
71**
72**********************************************************************/
73
74#ifndef QGL_H
75#define QGL_H
76
77#ifndef QT_H
78#include "qwidget.h"
79#include "qglcolormap.h"
80#endif // QT_H
81
82#if !defined( QT_MODULE_OPENGL ) || defined( QT_LICENSE_PROFESSIONAL )
83#define QM_EXPORT_OPENGL
84#else
85#define QM_EXPORT_OPENGL Q_EXPORT
86#endif
87
88#ifndef QT_NO_COMPAT
89#define QGL_VERSION 450
90#define QGL_VERSION_STR "4.5"
91QM_EXPORT_OPENGL inline const char *qGLVersion() {
92 qObsolete( 0, "qGLVersion", "qVersion" );
93 return QGL_VERSION_STR;
94}
95#endif
96
97#if defined(Q_WS_WIN)
98# include "qt_windows.h"
99#endif
100
101#if defined(Q_WS_MAC)
102#if !defined( QMAC_OPENGL_DOUBLEBUFFER )
103/* This macro is different now. If the macro is not defined QGLWidget will
104 * try to determine when you need double buffering. If set to 0 it will
105 * never double buffer and *can* be acclerated. If set to 1 (the default)
106 * it will always double buffer. Unlike before the value of this macro does
107 * not upset binary compatability either. */
108#if QT_MACOSX_VERSION &gt;= 0x1020
109# define QMAC_OPENGL_DOUBLEBUFFER 0
110#endif
111#endif
112# include &lt;OpenGL/gl.h&gt;
113# include &lt;OpenGL/glu.h&gt;
114#else
115# include &lt;GL/gl.h&gt;
116# include &lt;GL/glu.h&gt;
117#endif
118
119#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
120class QGLCmap;
121#endif
122
123class QPixmap;
124#if defined(Q_WS_X11)
125class QGLOverlayWidget;
126#endif
127
128// Namespace class:
129class QM_EXPORT_OPENGL QGL
130{
131public:
132 enum FormatOption {
133 DoubleBuffer = 0x0001,
134 DepthBuffer = 0x0002,
135 Rgba = 0x0004,
136 AlphaChannel = 0x0008,
137 AccumBuffer = 0x0010,
138 StencilBuffer = 0x0020,
139 StereoBuffers = 0x0040,
140 DirectRendering = 0x0080,
141 HasOverlay = 0x0100,
142 SingleBuffer = DoubleBuffer &lt;&lt; 16,
143 NoDepthBuffer = DepthBuffer &lt;&lt; 16,
144 ColorIndex = Rgba &lt;&lt; 16,
145 NoAlphaChannel = AlphaChannel &lt;&lt; 16,
146 NoAccumBuffer = AccumBuffer &lt;&lt; 16,
147 NoStencilBuffer = StencilBuffer &lt;&lt; 16,
148 NoStereoBuffers = StereoBuffers &lt;&lt; 16,
149 IndirectRendering = DirectRendering &lt;&lt; 16,
150 NoOverlay = HasOverlay &lt;&lt; 16
151 };
152};
153
154
155
156class QM_EXPORT_OPENGL QGLFormat : public QGL
157{
158public:
159 QGLFormat();
160 QGLFormat( int options, int plane = 0 );
161
162 bool doubleBuffer() const;
163 void setDoubleBuffer( bool enable );
164 bool depth() const;
165 void setDepth( bool enable );
166 bool rgba() const;
167 void setRgba( bool enable );
168 bool alpha() const;
169 void setAlpha( bool enable );
170 bool accum() const;
171 void setAccum( bool enable );
172 bool stencil() const;
173 void setStencil( bool enable );
174 bool stereo() const;
175 void setStereo( bool enable );
176 bool directRendering() const;
177 void setDirectRendering( bool enable );
178 bool hasOverlay() const;
179 void setOverlay( bool enable );
180
181 int plane() const;
182 void setPlane( int plane );
183
184 void setOption( FormatOption opt );
185 bool testOption( FormatOption opt ) const;
186
187 static QGLFormat defaultFormat();
188 static void setDefaultFormat( const QGLFormat&amp; f );
189
190 static QGLFormat defaultOverlayFormat();
191 static void setDefaultOverlayFormat( const QGLFormat&amp; f );
192
193 static bool hasOpenGL();
194 static bool hasOpenGLOverlays();
195
196 friend QM_EXPORT_OPENGL bool operator==( const QGLFormat&amp;,
197 const QGLFormat&amp; );
198 friend QM_EXPORT_OPENGL bool operator!=( const QGLFormat&amp;,
199 const QGLFormat&amp; );
200private:
201 uint opts;
202 int pln;
203};
204
205
206QM_EXPORT_OPENGL bool operator==( const QGLFormat&amp;, const QGLFormat&amp; );
207QM_EXPORT_OPENGL bool operator!=( const QGLFormat&amp;, const QGLFormat&amp; );
208
209class QM_EXPORT_OPENGL QGLContext : public QGL
210{
211public:
212 QGLContext( const QGLFormat&amp; format, QPaintDevice* device );
213 QGLContext( const QGLFormat&amp; format );
214 virtual ~QGLContext();
215
216 virtual bool create( const QGLContext* shareContext = 0 );
217 bool isValid() const;
218 bool isSharing() const;
219 virtual void reset();
220
221 QGLFormat format() const;
222 QGLFormat requestedFormat() const;
223 virtual void setFormat( const QGLFormat&amp; format );
224
225 virtual void makeCurrent();
226 virtual void swapBuffers() const;
227
228 QPaintDevice* device() const;
229
230 QColor overlayTransparentColor() const;
231
232 static const QGLContext* currentContext();
233
234protected:
235 virtual bool chooseContext( const QGLContext* shareContext = 0 );
236 virtual void doneCurrent(); // ### 4.0: make this public - needed for multithreading stuff
237
238#if defined(Q_WS_WIN)
239 virtual int choosePixelFormat( void* pfd, HDC pdc );
240#endif
241#if defined(Q_WS_X11)
242 virtual void* tryVisual( const QGLFormat&amp; f, int bufDepth = 1 );
243 virtual void* chooseVisual();
244#endif
245#if defined(Q_WS_MAC)
246 virtual void* chooseMacVisual(GDHandle);
247#endif
248
249 bool deviceIsPixmap() const;
250 bool windowCreated() const;
251 void setWindowCreated( bool on );
252 bool initialized() const;
253 void setInitialized( bool on );
254 void generateFontDisplayLists( const QFont &amp; fnt, int listBase );
255
256 uint colorIndex( const QColor&amp; c ) const;
257 void setValid( bool valid );
258 void setDevice( QPaintDevice *pDev );
259
260protected:
261#if defined(Q_WS_WIN)
262 HGLRC rc;
263 HDC dc;
264 WId win;
265 int pixelFormatId;
266 QGLCmap* cmap;
267#elif defined(Q_WS_X11) || defined(Q_WS_MAC)
268 void* vi;
269 void* cx;
270#if defined(Q_WS_X11)
271 Q_UINT32 gpm;
272#endif
273#endif
274 QGLFormat glFormat;
275 QGLFormat reqFormat;
276 static QGLContext* currentCtx;
277
278private:
279 void init( QPaintDevice *dev = 0 );
280 class Private {
281 public:
282 bool valid;
283 bool sharing;
284 bool initDone;
285 bool crWin;
286 QPaintDevice* paintDevice;
287 QColor transpColor;
288#ifdef Q_WS_MAC
289 QRect oldR;
290#endif
291 };
292 Private* d;
293
294 friend class QGLWidget;
295#ifdef Q_WS_MAC
296 void fixBufferRect();
297#endif
298
299private: // Disabled copy constructor and operator=
300 QGLContext() {}
301 QGLContext( const QGLContext&amp; ) {}
302 QGLContext&amp; operator=( const QGLContext&amp; ) { return *this; }
303};
304
305
306
307
308class QM_EXPORT_OPENGL QGLWidget : public QWidget, public QGL
309{
310 Q_OBJECT
311public:
312 QGLWidget( QWidget* parent=0, const char* name=0,
313 const QGLWidget* shareWidget = 0, WFlags f=0 );
314 QGLWidget( QGLContext *context, QWidget* parent, const char* name=0,
315 const QGLWidget* shareWidget = 0, WFlags f=0 );
316 QGLWidget( const QGLFormat&amp; format, QWidget* parent=0, const char* name=0,
317 const QGLWidget* shareWidget = 0, WFlags f=0 );
318 ~QGLWidget();
319
320 void qglColor( const QColor&amp; c ) const;
321 void qglClearColor( const QColor&amp; c ) const;
322
323 bool isValid() const;
324 bool isSharing() const;
325 virtual void makeCurrent();
326 void doneCurrent();
327
328 bool doubleBuffer() const;
329 virtual void swapBuffers();
330
331 QGLFormat format() const;
332#ifndef Q_QDOC
333 virtual void setFormat( const QGLFormat&amp; format );
334#endif
335
336 const QGLContext* context() const;
337#ifndef Q_QDOC
338 virtual void setContext( QGLContext* context,
339 const QGLContext* shareContext = 0,
340 bool deleteOldContext = TRUE );
341#endif
342
343 virtual QPixmap renderPixmap( int w = 0, int h = 0,
344 bool useContext = FALSE );
345 virtual QImage grabFrameBuffer( bool withAlpha = FALSE );
346
347 virtual void makeOverlayCurrent();
348 const QGLContext* overlayContext() const;
349
350 static QImage convertToGLFormat( const QImage&amp; img );
351
352 void setMouseTracking( bool enable );
353 virtual void reparent( QWidget* parent, WFlags f, const QPoint&amp; p,
354 bool showIt = FALSE );
355
356 const QGLColormap &amp; colormap() const;
357 void setColormap( const QGLColormap &amp; map );
358
359 void renderText( int x, int y, const QString &amp; str,
360 const QFont &amp; fnt = QFont(), int listBase = 2000 );
361 void renderText( double x, double y, double z, const QString &amp; str,
362 const QFont &amp; fnt = QFont(), int listBase = 2000 );
363public slots:
364 virtual void updateGL();
365 virtual void updateOverlayGL();
366
367protected:
368 virtual void initializeGL();
369 virtual void resizeGL( int w, int h );
370 virtual void paintGL();
371
372 virtual void initializeOverlayGL();
373 virtual void resizeOverlayGL( int w, int h );
374 virtual void paintOverlayGL();
375
376 void setAutoBufferSwap( bool on );
377 bool autoBufferSwap() const;
378
379 void paintEvent( QPaintEvent* );
380 void resizeEvent( QResizeEvent* );
381
382 virtual void glInit();
383 virtual void glDraw();
384
385private:
386 int displayListBase( const QFont &amp; fnt, int listBase );
387 void cleanupColormaps();
388 void init( QGLContext *context, const QGLWidget* shareWidget );
389 bool renderCxPm( QPixmap* pm );
390 QGLContext* glcx;
391 bool autoSwap;
392
393 QGLColormap cmap;
394
395#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
396 QGLContext* olcx;
397#elif defined(Q_WS_X11)
398 QGLOverlayWidget* olw;
399 friend class QGLOverlayWidget;
400#endif
401
402private: // Disabled copy constructor and operator=
403#if defined(Q_DISABLE_COPY)
404 QGLWidget( const QGLWidget&amp; );
405 QGLWidget&amp; operator=( const QGLWidget&amp; );
406#endif
407
408#if defined(Q_WS_MAC)
409private:
410 const QGLContext *slcx;
411 uint pending_fix : 1,
412 glcx_dblbuf : 2,
413 dblbuf : 1,
414 clp_serial : 15;
415 QPixmap *gl_pix;
416 QGLFormat req_format;
417
418 void macInternalRecreateContext( QGLContext *ctx,
419 const QGLContext* = NULL,
420 bool update = TRUE );
421 bool macInternalDoubleBuffer( bool fix = TRUE );
422 virtual void setRegionDirty( bool );
423 virtual void macWidgetChangedWindow();
424#endif
425private slots:
426 void macInternalFixBufferRect();
427};
428
429
430//
431// QGLFormat inline functions
432//
433
434inline bool QGLFormat::doubleBuffer() const
435{
436 return testOption( DoubleBuffer );
437}
438
439inline bool QGLFormat::depth() const
440{
441 return testOption( DepthBuffer );
442}
443
444inline bool QGLFormat::rgba() const
445{
446 return testOption( Rgba );
447}
448
449inline bool QGLFormat::alpha() const
450{
451 return testOption( AlphaChannel );
452}
453
454inline bool QGLFormat::accum() const
455{
456 return testOption( AccumBuffer );
457}
458
459inline bool QGLFormat::stencil() const
460{
461 return testOption( StencilBuffer );
462}
463
464inline bool QGLFormat::stereo() const
465{
466 return testOption( StereoBuffers );
467}
468
469inline bool QGLFormat::directRendering() const
470{
471 return testOption( DirectRendering );
472}
473
474inline bool QGLFormat::hasOverlay() const
475{
476 return testOption( HasOverlay );
477}
478
479//
480// QGLContext inline functions
481//
482
483inline bool QGLContext::isValid() const
484{
485 return d-&gt;valid;
486}
487
488inline void QGLContext::setValid( bool valid )
489{
490 d-&gt;valid = valid;
491}
492
493inline bool QGLContext::isSharing() const
494{
495 return d-&gt;sharing;
496}
497
498inline QGLFormat QGLContext::format() const
499{
500 return glFormat;
501}
502
503inline QGLFormat QGLContext::requestedFormat() const
504{
505 return reqFormat;
506}
507
508inline QPaintDevice* QGLContext::device() const
509{
510 return d-&gt;paintDevice;
511}
512
513inline bool QGLContext::deviceIsPixmap() const
514{
515 return d-&gt;paintDevice-&gt;devType() == QInternal::Pixmap;
516}
517
518
519inline bool QGLContext::windowCreated() const
520{
521 return d-&gt;crWin;
522}
523
524
525inline void QGLContext::setWindowCreated( bool on )
526{
527 d-&gt;crWin = on;
528}
529
530inline bool QGLContext::initialized() const
531{
532 return d-&gt;initDone;
533}
534
535inline void QGLContext::setInitialized( bool on )
536{
537 d-&gt;initDone = on;
538}
539
540inline const QGLContext* QGLContext::currentContext()
541{
542 return currentCtx;
543}
544
545//
546// QGLWidget inline functions
547//
548
549inline QGLFormat QGLWidget::format() const
550{
551 return glcx-&gt;format();
552}
553
554inline const QGLContext *QGLWidget::context() const
555{
556 return glcx;
557}
558
559inline bool QGLWidget::doubleBuffer() const
560{
561 return glcx-&gt;format().doubleBuffer();
562}
563
564inline void QGLWidget::setAutoBufferSwap( bool on )
565{
566 autoSwap = on;
567}
568
569inline bool QGLWidget::autoBufferSwap() const
570{
571 return autoSwap;
572}
573
574#endif
575</pre>
576<!-- eof -->
577<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.