📄 qglwidget.3qt
字号:
.TH QGLWidget 3qt "6 July 1999" "Troll Tech AS" \" -*- nroff -*-.\" Copyright 1992-1999 Troll Tech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQGLWidget \- Widget for rendering OpenGL graphics [Qt OpenGL Extension].SH SYNOPSIS.br.PP\fC#include <qgl.h>\fR.PPInherits QWidget and QGL..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQGLWidget\fR ( QWidget * " "parent" "=0, const char * " "name" "=0, const QGLWidget * " "shareWidget" " = 0, WFlags " "f" "=0 )".br.ti -1c.BI "\fBQGLWidget\fR ( const QGLFormat & " "format" ", QWidget * " "parent" "=0, const char * " "name" "=0, const QGLWidget * " "shareWidget" " = 0, WFlags " "f" "=0 )".br.ti -1c.BI "\fB~QGLWidget\fR ()".br.ti -1c.BI "void \fBqglColor\fR ( const QColor & c )".br.ti -1c.BI "void \fBqglClearColor\fR ( const QColor & c )".br.ti -1c.BI "bool \fBisValid\fR () const".br.ti -1c.BI "bool \fBisSharing\fR () const".br.ti -1c.BI "virtual void \fBmakeCurrent\fR ()".br.ti -1c.BI "bool \fBdoubleBuffer\fR () const".br.ti -1c.BI "virtual void \fBswapBuffers\fR ()".br.ti -1c.BI "QGLFormat \fBformat\fR () const".br.ti -1c.BI "virtual void \fBsetFormat\fR ( const QGLFormat & format )".br.ti -1c.BI "const QGLContext* \fBcontext\fR () const".br.ti -1c.BI "virtual void \fBsetContext\fR ( QGLContext * " "context" ", const QGLContext * " "shareContext" " = 0, bool " "deleteOldContext" " = TRUE )".br.ti -1c.BI "virtual QPixmap \fBrenderPixmap\fR ( int " "w" " = 0, int " "h" " = 0, bool " "useContext" " = FALSE )".br.in -1c.SS "Public Slots".in +1c.ti -1c.BI "virtual void \fBupdateGL\fR ()".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "virtual void \fBinitializeGL\fR ()".br.ti -1c.BI "virtual void \fBpaintGL\fR ()".br.ti -1c.BI "virtual void \fBresizeGL\fR ( int " "w" ", int h )".br.ti -1c.BI "void \fBsetAutoBufferSwap\fR ( bool on )".br.ti -1c.BI "bool \fBautoBufferSwap\fR () const".br.ti -1c.BI "virtual void \fBpaintEvent\fR ( QPaintEvent * )".br.ti -1c.BI "virtual void \fBresizeEvent\fR ( QResizeEvent * )".br.ti -1c.BI "virtual void \fBglInit\fR ()".br.ti -1c.BI "virtual void \fBglDraw\fR ()".br.in -1c.SH DESCRIPTIONThis class is defined in the \fBQt OpenGL Extension\fR, which can be found in the \fCqt/extensions\fR directory. It is not included in the main Qt API..PPThe QGLWidget class is a widget for rendering OpenGL graphics..PPQGLWidget provides functionality for displaying OpenGL graphics integrated in a Qt application. It is very simple to use: you inherit from it and use the subclass like any other QWidget, only that instead of drawing the widget's contents using QPainter & al., you use the standard OpenGL rendering commands..PPQGLWidget provides three convenient virtual functions that you can reimplement in your subclass to perform the typical OpenGL tasks:.TPpaintGL() - Render the OpenGL scene. Gets called whenever the widget needs to be updated..TPresizeGL() - Set up OpenGL viewport, projection etc. Gets called whenever the the widget has been resized (and also when it shown for the first time, since all newly created widgets get a resize event automatically)..TPinitializeGL() - Set up the OpenGL rendering context, define display lists etc. Gets called once before the first time resizeGL() or paintGL() is called..PPHere is a rough outline of how your QGLWidget subclass may look:.PP.nf.br class MyGLDrawer : public QGLWidget.br {.br Q_OBJECT // must include this if you use Qt signals/slots.br.br public:.br MyGLDrawer( QWidget *parent, const char *name ).br : QGLWidget(parent,name) {}.br.br protected:.br.br void initializeGL().br {.br // 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 };.fi.PPIf you need to trigger a repaint from other places than paintGL() (a typical example is when using timers to animate scenes), you should call the widget's updateGL() function..PPWhen paintGL(), resizeGL() or initializeGL() is called, your widget's OpenGL rendering context has been made current. If you need to call the standard OpenGL API functions from other places (e.g. in your widget's constructor), you must call makeCurrent() first..PPQGLWidget provides advanced functions for requesting a new display format, and you can even set a new rendering context..PPYou can achieve sharing of OpenGL display lists between QGLWidgets, see the documentation of the QGLWidget constructors for details..SH MEMBER FUNCTION DOCUMENTATION.SH "QGLWidget::QGLWidget ( QWidget * parent=0, const char * name=0, const QGLWidget * shareWidget = 0, WFlags f=0 )"Constructs an OpenGL widget with a \fIparent\fR widget and a \fIname.\fR.PPThe default format is used. The widget will be invalid if the system has no OpenGL support..PPThe \fIparent, name\fR and \fIf\fR arguments are passed to the QWidget constructor..PPIf the \fIshareWidget\fR parameter points to a valid QGLWidget, this widget will share OpenGL display lists with \fIshareWidget.\fR Note: If this widget and \fIshareWidget\fR has different formats, display list sharing may fail. You can check whether display list sharing succeeded by using the isSharing() method..PPNote: Initialization of OpenGL rendering state etc. should be done by overriding the initializeGL() function, not in the constructor of your QGLWidget subclass..PPSee also: QGLFormat::defaultFormat()..SH "QGLWidget::QGLWidget ( const QGLFormat & format, QWidget * parent=0, const char * name=0, const QGLWidget * shareWidget = 0, WFlags f=0 )"Constructs an OpenGL widget with a \fIparent\fR widget and a \fIname.\fR.PPThe \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..PPThe widget will be invalid if the system has no OpenGL support..PPThe \fIparent, name\fR and \fIf\fR arguments are passed to the QWidget constructor..PPIf the \fIshareWidget\fR parameter points to a valid QGLWidget, this widget will share OpenGL display lists with \fIshareWidget.\fR Note: If this widget and \fIshareWidget\fR has different formats, display list sharing may fail. You can check whether display list sharing succeeded by using the isSharing() method..PPNote: Initialization of OpenGL rendering state etc. should be done by overriding the initializeGL() function, not in the constructor of your QGLWidget subclass..PPSee also: QGLFormat::defaultFormat() and isValid()..SH "QGLWidget::~QGLWidget ()"Destroys the widget..SH "bool QGLWidget::autoBufferSwap () const \fC[protected]\fR"Returns TRUE if the widget is doing automatic GL buffer swapping..PPSee also: setAutoBufferSwap()..SH "const QGLContext * QGLWidget::context () const"Returns the current context..PPSee also: setContext()..SH "bool QGLWidget::doubleBuffer () const"Returns TRUE if the contained GL rendering context has double buffering..PPSee also: QGLFormat::doubleBuffer()..SH "QGLFormat QGLWidget::format () const"Returns the format of the contained GL rendering context..PPSee also: setFormat()..SH "void QGLWidget::glDraw () \fC[virtual protected]\fR"Executes the virtual function paintGL(), initializing first as necessary..SH "void QGLWidget::glInit () \fC[virtual protected]\fR"Initializes OpenGL for this widget's context. Calls the virtual function initializeGL()..SH "void QGLWidget::initializeGL () \fC[virtual protected]\fR"This virtual function is called one time before the first call to paintGL() or resizeGL(), and then one time whenever the widget has been assigned a new QGLContext. Reimplement it in a subclass..PPThis function should take care of setting any required OpenGL context rendering flags, defining display lists, etc..PPThere is no need to call makeCurrent() because this has already been done when this function is called..SH "bool QGLWidget::isSharing () const"Returns TRUE if display list sharing with another QGLWidget was requested in the constructor, and the GL system was able to provide it. The GL system may fail to provide display list sharing if the two QGLWidgets use different formats..PPSee also: format()..SH "bool QGLWidget::isValid () const"Returns TRUE if the widget has a valid GL rendering context. A widget will be invalid if the system has no OpenGL support.SH "void QGLWidget::makeCurrent () \fC[virtual]\fR"Makes this widget the current widget for OpenGL operations. I.e. makes this widget's rendering context the current OpenGL rendering context..SH "void QGLWidget::paintEvent ( QPaintEvent * ) \fC[virtual protected]\fR"Handles paint events. Will cause the virtual paintGL() fucntion to be called, initializing first as necessary..PPReimplemented from QWidget..SH "void QGLWidget::paintGL () \fC[virtual protected]\fR"This virtual function is called whenever the widget needs to be painted. Reimplement it in a subclass..PPThere is no need to call makeCurrent() because this has already been done when this function is called..SH "void QGLWidget::qglClearColor ( const QColor & c )"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.PPSee also: qglColor() and QColor..SH "void QGLWidget::qglColor ( const QColor & c )"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.PPSee also: qglClearColor() and QColor..SH "QPixmap QGLWidget::renderPixmap ( int w = 0, int h = 0, bool useContext = FALSE ) \fC[virtual]\fR"Renders the current scene on a pixmap and returns it..PPYou may use this method on both visible and invisible QGLWidgets..PPThis method will create a pixmap and a temporary QGLContext to render on it. Then, initializeGL(), resizeGL(), and paintGL() are called on this context. Finally, the widget's original GL context is restored..PPThe size of the pixmap will be width \fIw\fR and height \fIh.\fR If any of those are 0 (the default), the pixmap will have the same size as the widget..PPIf \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. Use only if you know what you are doing..PPBugs and limitations:.TPMay give unexpected results if the depth of the GL rendering context is different from the depth of the desktop..SH "void QGLWidget::resizeEvent ( QResizeEvent * ) \fC[virtual protected]\fR"Handles resize events. Calls the virtual function resizeGL()..PPReimplemented from QWidget..SH "void QGLWidget::resizeGL ( int width, int height ) \fC[virtual protected]\fR"This virtual function is called whenever the widget has been resized. Reimplement it in a subclass..PPThere is no need to call makeCurrent() because this has already been done when this function is called..SH "void QGLWidget::setAutoBufferSwap ( bool on ) \fC[protected]\fR"Turns on or off the automatic GL buffer swapping. If on, and the widget is using a double-buffered format, the background and foreground GL buffers will automatically be swapped after each time the paintGL() function has been called..PPThe buffer auto-swapping is on by default..PPSee also: autoBufferSwap(), doubleBuffer() and swapBuffers()..SH "void QGLWidget::setContext ( QGLContext * context, const QGLContext * shareContext = 0, bool deleteOldContext = TRUE ) \fC[virtual]\fR"Sets a new context for this widget. The QGLContext \fIcontext\fR must be created using \fInew.\fR QGLWidget will delete \fIcontext\fR when another context is set or when the widget is destroyed..PPIf \fIcontext\fR is invalid, QGLContext::create() is performed on it. The initializeGL() function will then be executed for the new context before the first resizeGL() or paintGL()..PPIf \fIcontext\fR is invalid, this method will try to keep any existing display list sharing with other QGLWidgets this widget currently has, or (if \fIshareContext\fR points to a valid context) start display list sharing with that context, but it may fail. Use isSharing() to test..PPIf \fIdeleteOldContext\fR is TRUE (the default), the existing context will be deleted. You may use FALSE here if you have kept a pointer to the old context (as returned by context()), and want to restore that context later..PPSee also: context(), setFormat() and isSharing()..SH "void QGLWidget::setFormat ( const QGLFormat & format ) \fC[virtual]\fR"Sets a new format for this widget..PPIf 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 rendering context format obtained..PPThe widget will be assigned a new QGLContext, and the initializeGL() function will be executed for this new context before the first resizeGL() or paintGL()..PPThis method will try to keep any existing display list sharing with other QGLWidgets, but it may fail. Use isSharing() to test..PPSee also: format(), setContext(), isSharing() and isValid()..SH "void QGLWidget::swapBuffers () \fC[virtual]\fR"Swaps the screen contents with an off-screen buffer. Works only if the widget's format specifies double buffer mode..PPNormally, there is no need to explicitly call this function, because it is done automatically after each widget repaint, i.e. after each time paintGL() has been executed..PPSee also: doubleBuffer(), setAutoBufferSwap() and QGLFormat::setDoubleBuffer()..SH "void QGLWidget::updateGL () \fC[virtual slot]\fR"Updates the widget by calling glDraw()..SH "SEE ALSO".BR http://www.troll.no/qt/qglwidget.html.SH COPYRIGHTCopyright 1992-1999 Troll Tech AS. See the license file included inthe distribution for a complete license statement..SH AUTHORGenerated automatically from the source code.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -