⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgl.cpp

📁 qtopia-phone-2.2.0 下支持的opengl源程序。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
  plane. The color's RGB values are meaningless, of course.  The returned QColor object will generally only work as expected when  passed as the argument to QGLWidget::qglColor() or  QGLWidget::qglClearColor(). Under certain circumstances it can also  be used to draw transparent graphics with a QPainter; see the  "overlay_x11" example for details.*//*!  Creates the GL context. Returns TRUE if it was successful in  creating a GL rendering context on the paint device specified in the  constructor, otherwise FALSE is returned (the context is invalid).  After successful creation, format() returns the set of features of  the created GL rendering context.  If \a shareContext points to a valid QGLContext, this method will  try to establish OpenGL display list sharing between this context  and \a shareContext. Note that this may fail if the two contexts  have different formats. Use isSharing() to test.  <strong>Implementation note:</strong> Initialization of C++ class members  usually takes place in the class constructor. QGLContext is an exception  because it must be simple to customize. The virtual functions  chooseContext() (and chooseVisual() for X11) can be reimplemented in a  subclass to select a particular context. The trouble is that virtual  functions are not properly called during construction (which is indeed  correct C++), hence we need a create() function.  \sa chooseContext(), format(), isValid()*/bool QGLContext::create( const QGLContext* shareContext ){    reset();    valid = chooseContext( shareContext );    return valid;}/*!  \fn bool QGLContext::chooseContext( const QGLContext* shareContext = 0 )  This semi-internal function is called by create(). It creates a  system-dependent OpenGL handle that matches the specified \link  format() format\endlink as closely as possible.  <strong>Windows</strong>: Calls choosePixelFormat() which finds a  matching pixel format identifier.  <strong>X11</strong>: Calls chooseVisual() which finds an appropriate  X visual.  choosePixelFormat() and chooseVisual() can be reimplemented in a  subclass if you need to choose a very custom context.*//*!  \fn void QGLContext::reset()  Resets the context and makes it invalid.  \sa create(), isValid()*//*!  \fn void QGLContext::makeCurrent()  Makes this context the current OpenGL rendering context.  All GL  functions you call operate on this context until another context is  made current.*//*!  \fn void QGLContext::swapBuffers() const  Swaps the screen contents with an off-screen buffer. Works only if  the context is in double buffer mode.  \sa QGLFormat::setDoubleBuffer()*//*!  \fn void QGLContext::doneCurrent()  Makes no GL context the current context. Normally, you do not need  to call this function, QGLContext calls it as necessary.*//*!  \fn QPaintDevice* QGLContext::device() const  Returns the paint device set for this context.  \sa QGLContext::QGLContext()*//*****************************************************************************  QGLWidget implementation *****************************************************************************//*!  \class QGLWidget qgl.h  \brief The QGLWidget class is a widget for rendering OpenGL graphics.  \module OpenGL  QGLWidget 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.  QGLWidget provides three convenient virtual functions that you can  reimplement in your subclass to perform the typical OpenGL tasks:  <ul>  <li> paintGL() - Render the OpenGL scene. Gets called whenever the widget  needs to be updated.  <li> resizeGL() - 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).  <li> initializeGL() - Set up the OpenGL rendering context, define display  lists etc. Gets called once before the first time resizeGL() or  paintGL() is called.  </ul>  Here is a rough outline of how your QGLWidget subclass may look:  \code    class MyGLDrawer : public QGLWidget    {        Q_OBJECT	// must include this if you use Qt signals/slots    public:        MyGLDrawer( QWidget *parent, const char *name )	    : QGLWidget(parent,name) {}    protected:        void initializeGL()	{	  // Set up the rendering context, define display lists etc.:	  ...	  glClearColor( 0.0, 0.0, 0.0, 0.0 );	  glEnable(GL_DEPTH_TEST);	  ...	}	void resizeGL( int w, int h )	{	  // setup viewport, projection etc.:	  glViewport( 0, 0, (GLint)w, (GLint)h );	  ...	  glFrustum( ... );	  ...	}        void paintGL()	{	  // draw the scene:	  ...	  glRotatef( ... );	  glMaterialfv( ... );	  glBegin( GL_QUADS );	  glVertex3f( ... );	  glVertex3f( ... );	  ...	  glEnd();	  ...	}    };  \endcode  If you need to trigger a repaint from other places than paintGL() (a  typical example is when using \link QTimer timers\endlink to animate  scenes), you should call the widget's updateGL() function.  When 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.  QGLWidget provides advanced functions for requesting a new display  \link QGLFormat format\endlink, and you can even set a new rendering  \link QGLContext context\endlink.  You can achieve sharing of OpenGL display lists between QGLWidgets,  see the documentation of the QGLWidget constructors for details.  <b>About Overlays:</b> The QGLWidget can create a GL overlay context  in addition to the normal context, if overlays are supported by the  underlying system.  If you want to use overlays, you specify it in the \link QGLFormat  format\endlink. (Note: Overlay must be requested in the format  passed to the QGLWidget constructor). Your GL widget should also  implement some or all of these virtual methods:  <ul>  <li> paintOverlayGL()  <li> resizeOverlayGL()  <li> initializeOverlayGL()  </ul>  These methods work in the same way as the normal paintGL() &  al. functions, only that they will be called when with the overlay  context made current. You can explicitly make the overlay context  current by using makeOverlayCurrent(), and you can access the  overlay context directly (e.g. to ask for its transparent color) by  calling overlayContext().  Note: QGLWidget overlay support is currently implemented only for  the X11 window system. The Windows implementation is experimental.  Note: On X servers where the default visual is in an overlay plane,  non-GL Qt windows can also be used for overlays; see the "overlay_x11"  example program for details.    Note: Reparenting QGLWidgets under Windows does not work. This will  be improved in Qt 3.0. If you really need to change the widget  hierarchy after widget creation, simply destroy the old instance and  create a new one with the new parent.*//*!  Constructs an OpenGL widget with a \a parent widget and a \a name.  The \link QGLFormat::defaultFormat() default format\endlink is  used. The widget will be \link isValid() invalid\endlink if the  system has no \link QGLFormat::hasOpenGL() OpenGL support\endlink.  The \e parent, \e name and \e f arguments are passed to the QWidget  constructor.  If the \a shareWidget parameter points to a valid QGLWidget, this  widget will share OpenGL display lists with \a shareWidget. Note: If  this widget and \a shareWidget has different \link format()  formats\endlink, display list sharing may fail. You can check  whether display list sharing succeeded by using the isSharing()  method.  Note: Initialization of OpenGL rendering state etc. should be done  by overriding the initializeGL() function, not in the constructor of  your QGLWidget subclass.  \sa QGLFormat::defaultFormat()*/QGLWidget::QGLWidget( QWidget *parent, const char *name,		      const QGLWidget* shareWidget, WFlags f )    : QWidget( parent, name, f | 0x10000000 )	// WWinOwnDC{    init( QGLFormat::defaultFormat(), shareWidget );}/*!  Constructs an OpenGL widget with a \a parent widget and a \a name.  The \a format argument specifies the desired \link QGLFormat  rendering options \endlink. If the underlying OpenGL/Window system  cannot satisfy all the features requested in \a format, the nearest  subset of features will be used. After creation, the format() method  will return the actual format obtained.  The widget will be \link isValid() invalid\endlink if the  system has no \link QGLFormat::hasOpenGL() OpenGL support\endlink.  The \e parent, \e name and \e f arguments are passed to the QWidget  constructor.  If the \a shareWidget parameter points to a valid QGLWidget, this  widget will share OpenGL display lists with \a shareWidget. Note: If  this widget and \a shareWidget has different \link format()  formats\endlink, display list sharing may fail. You can check  whether display list sharing succeeded by using the isSharing()  method.  Note: Initialization of OpenGL rendering state etc. should be done  by overriding the initializeGL() function, not in the constructor of  your QGLWidget subclass.  \sa QGLFormat::defaultFormat(), isValid()*/QGLWidget::QGLWidget( const QGLFormat &format, QWidget *parent,		      const char *name, const QGLWidget* shareWidget,		      WFlags f )    : QWidget( parent, name, f | 0x10000000 )	// WWinOwnDC{    init( format, shareWidget );}/*!  Destroys the widget.*/QGLWidget::~QGLWidget(){#if defined(GLX_MESA_release_buffers) && defined(QGL_USE_MESA_EXT)    bool doRelease = ( glcx && glcx->windowCreated() );#endif    delete glcx;#if defined(Q_WGL)    delete olcx;#endif#if defined(GLX_MESA_release_buffers) && defined(QGL_USE_MESA_EXT)    if ( doRelease )	glXReleaseBuffersMESA( x11Display(), winId() );#endif}/*!  \fn QGLFormat QGLWidget::format() const  Returns the format of the contained GL rendering context.*//*!  \fn bool QGLWidget::doubleBuffer() const  Returns TRUE if the contained GL rendering context has double buffering.  \sa QGLFormat::doubleBuffer()*//*!  \fn void QGLWidget::setAutoBufferSwap( bool on )  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.  The buffer auto-swapping is on by default.  \sa autoBufferSwap(), doubleBuffer(), swapBuffers()*//*!  \fn bool QGLWidget::autoBufferSwap() const  Returns TRUE if the widget is doing automatic GL buffer swapping.  \sa setAutoBufferSwap()*//*!  \fn 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 \link  QGLFormat::hasOpenGL() OpenGL support\endlink.*/bool QGLWidget::isValid() const{    return glcx->isValid();}/*!  \fn 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.  \sa format()*/bool QGLWidget::isSharing() const{    return glcx->isSharing();}/*!  \fn void QGLWidget::makeCurrent()  Makes this widget the current widget for OpenGL  operations. I.e. makes this widget's rendering context the current  OpenGL rendering context.*/void QGLWidget::makeCurrent(){    glcx->makeCurrent();}/*!  \fn void QGLWidget::swapBuffers()  Swaps the screen contents with an off-screen buffer. Works only if  the widget's format specifies double buffer mode.  Normally, 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.  \sa doubleBuffer(), setAutoBufferSwap(), QGLFormat::setDoubleBuffer()*/void QGLWidget::swapBuffers(){    glcx->swapBuffers();}/*!  \fn const QGLContext* QGLWidget::overlayContext() const  Returns the overlay context of this widget, or 0 if this widget has  no overlay.  \sa context()*//*!  \fn void QGLWidget::makeOverlayCurrent()  Makes the overlay context of this widget current. Use this if you  need to issue OpenGL commands to the overlay context outside of  initializeOverlayGL(), resizeOverlayGL() and paintOverlayGL().

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -