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

📄 qgl.cpp

📁 qtopia-phone-2.2.0 下支持的opengl源程序。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/****************************************************************************** $Id: qt/src/opengl/qgl.cpp   2.3.12   edited 2005-10-27 $**** Implementation of OpenGL classes for Qt**** Created : 970112**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of the opengl module of the Qt GUI Toolkit.**** This file may be distributed under the terms of the Q Public License** as defined by Trolltech AS of Norway and appearing in the file** LICENSE.QPL included in the packaging of this file.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid Qt Enterprise Edition licenses may use this** file in accordance with the Qt Commercial License Agreement provided** with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for**   information about Qt Commercial License Agreements.** See http://www.trolltech.com/qpl/ for QPL licensing information.** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "qgl.h"#include <qpixmap.h>#include <qpaintdevicemetrics.h>#include <qimage.h>static QGLFormat* qgl_default_format = 0;static QGLFormat* qgl_default_overlay_format = 0;/*!  \obsolete*/const char *qGLVersion(){    qObsolete( 0, "qGLVersion", "qVersion" );    return QGL_VERSION_STR;}/*! \class QGL qgl.h  \brief The QGL class is a namespace for miscellaneous identifiers  in the Qt OpenGL module.  \module OpenGL  Normally, you can ignore this class. QGLWidget and the other OpenGL  module classes inherit it, so when you make your own QGLWidget  subclass, you can use the identifiers in the QGL namespace without  qualification.  However, occasionally you may find yourself in situations where you  need ot refer to these identifiers from outside the QGL namespace  scope, e.g. in static utility functions. In such cases, simply write  e.g. \c QGL::DoubleBuffer instead just \c DoubleBuffer.*//*****************************************************************************  QGLFormat implementation *****************************************************************************//*!  \class QGLFormat qgl.h  \brief The QGLFormat class specifies the display format of an OpenGL  rendering context.  \module OpenGL  A display format has several characteristics:  <ul>  <li> \link setDoubleBuffer() Double or single buffering.\endlink  <li> \link setDepth() Depth buffer.\endlink  <li> \link setRgba() RGBA or color index mode.\endlink  <li> \link setAlpha() Alpha channel.\endlink  <li> \link setAccum() Accumulation buffer.\endlink  <li> \link setStencil() Stencil buffer.\endlink  <li> \link setStereo() Stereo buffers.\endlink  <li> \link setDirectRendering() Direct rendering.\endlink  <li> \link setOverlay() Presence of an overlay.\endlink  <li> \link setPlane() The plane of an overlay format.\endlink  </ul>  You create and tell a QGLFormat object what rendering options  you want from an OpenGL rendering context.  OpenGL drivers or accelerated hardware may or may not support  advanced features like alpha channel or stereographic viewing. If  you request some features the driver/hardware does not provide when  you create a QGLWidget, you will get the a rendering context with  the nearest subset of features.  There are different ways of defining the display characteristics  of a rendering context. One is to create a QGLFormat and make  it default for the entire application:  \code    QGLFormat f;    f.setAlpha( TRUE );    f.setStereo( TRUE );    QGLFormat::setDefaultFormat( f );  \endcode  Or you can specify the desired format when creating an object of  your QGLWidget subclass:  \code    QGLFormat f;    f.setDoubleBuffer( FALSE );                 // I want single buffer    f.setDirectRendering( FALSE );              // I want software rendering    MyGLWidget* myWidget = new MyGLWidget( f, ... );  \endcode  After the widget has been created, you can test which of the  requested features the system was able to provide:  \code    QGLFormat f;    f.setOverlay( TRUE );    f.setStereo( TRUE );    MyGLWidget* myWidget = new MyGLWidget( f, ... );    if ( !w->format().stereo() ) {        // ok, goggles off        if ( !w->format().hasOverlay() ) {            qFatal( "Cool hardware wanted" );        }    }  \endcode  \sa QGLContext, QGLWidget*//*!  Constructs a QGLFormat object with the factory default settings:  <ul>  <li> \link setDoubleBuffer() Double buffer:\endlink Enabled.  <li> \link setDepth() Depth buffer:\endlink Enabled.  <li> \link setRgba() RGBA:\endlink Enabled (i.e. color index disabled).  <li> \link setAlpha() Alpha channel:\endlink Disabled.  <li> \link setAccum() Accumulator buffer:\endlink Disabled.  <li> \link setStencil() Stencil buffer:\endlink Disabled.  <li> \link setStereo() Stereo:\endlink Disabled.  <li> \link setDirectRendering() Direct rendering:\endlink Enabled.  <li> \link setOverlay() Overlay:\endlink Disabled.  <li> \link setPlane() Plane:\endlink 0 (i.e. normal plane).  </ul>*/QGLFormat::QGLFormat(){    opts = DoubleBuffer | DepthBuffer | Rgba | DirectRendering;    pln = 0;}/*!  Creates a QGLFormat object that is a copy of the current \link  defaultFormat() application default format\endlink.  If \a options is not 0, this copy will be modified by these format options.  The \a options parameter must be FormatOption values OR'ed together.  This constructor makes it easy to specify a certain desired format  in classes derived from QGLWidget, for example:  \code    // The rendering in MyGLWidget depends on using    // stencil buffer and alpha channel    MyGLWidget::MyGLWidget( QWidget* parent, const char* name )        : QGLWidget( QGLFormat( StencilBuffer | AlphaChannel ), parent, name )    {      if ( !format().stencil() )        qWarning( "Could not get stencil buffer; results will be suboptimal" );      if ( !format().alphaChannel() )        qWarning( "Could not get alpha channel; results will be suboptimal" );      ...   }  \endcode  Note that there exists FormatOption values for both turning on and  off all format settings, e.g. DepthBuffer and NoDepthBuffer,  DirectRendering and IndirectRendering, etc.  \sa defaultFormat(), setOption()*/QGLFormat::QGLFormat( int options, int plane ){    uint newOpts = options;    opts = defaultFormat().opts;    opts |= ( newOpts & 0xffff );    opts &= ~( newOpts >> 16 );    pln = plane;}/*!  \fn bool QGLFormat::doubleBuffer() const  Returns TRUE if double buffering is enabled, otherwise FALSE.  Double buffering is enabled by default.  \sa setDoubleBuffer()*//*!  Sets double buffering if \a enable is TRUE or single buffering if  \a enable is FALSE.  Double buffering is enabled by default.  Double buffering is a technique where graphics is rendered to an off-screen  buffer and not directly to the screen. When the drawing has been  completed, the program calls a swapBuffers function to exchange the screen  contents with the buffer. The result is flicker-free drawing and often  better performance.  \sa doubleBuffer(), QGLContext::swapBuffers(), QGLWidget::swapBuffers()*/void QGLFormat::setDoubleBuffer( bool enable ){    setOption( enable ? DoubleBuffer : SingleBuffer );}/*!  \fn bool QGLFormat::depth() const  Returns TRUE if the depth buffer is enabled, otherwise FALSE.  The depth buffer is enabled by default.  \sa setDepth()*//*!  Enables the depth buffer if \a enable is TRUE, or disables  it if \a enable is FALSE.  The depth buffer is enabled by default.  The purpose of a depth buffer (or z-buffering) is to remove hidden  surfaces. Pixels are assigned z values based on the distance to the  viewer. A pixel with a high z value is closer to the viewer than a  pixel with a low z value. This information is used to decide whether  to draw a pixel or not.  \sa depth()*/void QGLFormat::setDepth( bool enable ){    setOption( enable ? DepthBuffer : NoDepthBuffer );}/*!  \fn bool QGLFormat::rgba() const  Returns TRUE if RGBA color mode is set, or FALSE if color index  mode is set. The default color mode is RGBA.  \sa setRgba()*//*!  Sets RGBA mode if \a enable is TRUE, or color index mode if \a enable  is FALSE.  The default color mode is RGBA.  RGBA is the preferred mode for most OpenGL applications.  In RGBA color mode you specify colors as a red + green + blue + alpha  quadruplet.  In color index mode you specify an index into a color lookup table.  \sa rgba()*/void QGLFormat::setRgba( bool enable ){    setOption( enable ? Rgba : ColorIndex );}/*!  \fn bool QGLFormat::alpha() const  Returns TRUE if the alpha channel of the framebuffer is enabled,  otherwise FALSE.  The alpha channel is disabled by default.  \sa setAlpha()*//*!  Enables the alpha channel of the framebuffer if \a enable is TRUE,  or disables it if \a enable is FALSE.  The alpha buffer is disabled by default.  The alpha channel is typically used for implementing transparency or  translucency.  The A in RGBA specifies the transparency of a pixel.  \sa alpha()*/void QGLFormat::setAlpha( bool enable ){    setOption( enable ? AlphaChannel : NoAlphaChannel );}/*!  \fn bool QGLFormat::accum() const  Returns TRUE if the accumulation buffer is enabled, otherwise FALSE.  The accumulation buffer is disabled by default.  \sa setAccum()*//*!  Enables the accumulation buffer if \a enable is TRUE, or disables  it if \a enable is FALSE.  The accumulation buffer is disabled by default.  The accumulation buffer is used for create blur effects and  multiple exposures.  \sa accum()*/void QGLFormat::setAccum( bool enable ){    setOption( enable ? AccumBuffer : NoAccumBuffer );}/*!  \fn bool QGLFormat::stencil() const  Returns TRUE if the stencil buffer is enabled, otherwise FALSE.  The stencil buffer is disabled by default.  \sa setStencil()*//*!  Enables the stencil buffer if \a enable is TRUE, or disables  it if \a enable is FALSE.  The stencil buffer is disabled by default.  The stencil buffer masks away drawing from certain parts of  the screen.  \sa stencil()*/void QGLFormat::setStencil( bool enable ){    setOption( enable ? StencilBuffer: NoStencilBuffer );}/*!  \fn bool QGLFormat::stereo() const  Returns TRUE if stereo buffering is enabled, otherwise FALSE.  Stereo buffering is disabled by default.  \sa setStereo()*//*!  Enables stereo buffering if \a enable is TRUE, or disables  it if \a enable is FALSE.  Stereo buffering is disabled by default.  Stereo buffering provides extra color buffers to generate left-eye  and right-eye images.  \sa stereo()*/void QGLFormat::setStereo( bool enable ){    setOption( enable ? StereoBuffers : NoStereoBuffers );}/*!  \fn bool QGLFormat::directRendering() const  Returns TRUE if direct rendering is enabled, otherwise FALSE.  Direct rendering is enabled by default.  \sa setDirectRendering()*//*!  Enables direct rendering if \a enable is TRUE, or disables  it if \a enable is FALSE.  Direct rendering is enabled by default.  Enabling this option will make OpenGL bypass the underlying window  system and render directly from hardware to the screen, if this is  supported by the system.  \sa directRendering()*/void QGLFormat::setDirectRendering( bool enable ){    setOption( enable ? DirectRendering : IndirectRendering );}/*!  \fn bool QGLFormat::hasOverlay() const  Returns TRUE if overlay plane is enabled, otherwise FALSE.  Overlay is disabled by default.  \sa setOverlay()*//*!  Enables an overlay plane if \a enable is TRUE; otherwise disables it.  Enabling the overlay plane will cause QGLWidget to create an

⌨️ 快捷键说明

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