QOpenGLFunctions的使用(2)

  前一小结请参考:QOpenglFuncations(1) www.icmzn.com

  本小节介绍相关的类:

1. The QGLContext class

  The QGLContext class包装了OpenGL的渲染环境类,即所有的QOpengl的绘制都在该环境中进行。

  An OpenGL rendering context is a complete set of OpenGL state variables. The rendering context‘s format is set in the constructor, but it can also be set later with setFormat(). The format options that are actually set are returned by format(); the options you asked for are returned by requestedFormat(). Note that after a QGLContext object has been constructed, the actual OpenGL context must be created by explicitly calling the create() function. ThemakeCurrent() function makes this context the current rendering context. You can make no context current using doneCurrent(). The reset() function will reset the context and make it invalid.

  OpenGL渲染换金,就是一个完整的OpenGL的状态变量集合。 在构造函数中QGLContext::QGLContext(const QGLFormat & format)需要指定渲染的格式,也可以通过setFormat()来进行后续的设置。实际设置的format options可以通过format()返回。而options则通过requestFormat()来返回。注意: 一旦QGLComtext 环境对象构造完毕,则需要通过显示调用create()函数来创建Opengl的实际的环境变量

inline QGLContext* createOpenGLContext()
{
    QOpenGLContext *context = new QOpenGLContext();
    QSurfaceFormat format;
    format.setVersion(2,1);
    format.setProfile(QSurfaceFormat::CompatibilityProfile);
    context->setFormat(format);
    QGLContext *result = QGLContext::fromOpenGLContext(context);
    result->create();
    return result;
}

  makeCurrent() 函数作用就是将该环境变量作为当前的渲染环境变量,这样所有的GL函数都可以在该环境变量下操作。可以在非main UI 线程之外的线程调用这个方法,从而确保从UI线程中将该环境变量设置为相关的线程中,从而在线程中完成相应的绘制。void QGLContext::moveToThread(QThread * thread)

  可以通过使用doneCurrent()函数来设置当前环境中空的GL环境变量。正常情况下不需要调用该函数,QGLContext会自动调用。

  If you‘re using double buffering you can swap the screen contents with the off-screen buffer using swapBuffers().

  如果使用双缓存方式来使用OpenGGL,则在off-screen 缓存中使用swapBuffers()函数。void QGLContext::swapBuffers() const,作用是完成OpenGL 一帧数据的渲染,确保再次调用makeCurrent(),然后在开始新的绘制。

  注意:QGLContext 不是线程安全的

2. The QSurface class

  The QSurface class is an abstraction of renderable surfaces in Qt.

  The size of the surface is accessible with the size() function。即返回Surface的像素数量size。The rendering specific attributes of the surface are accessible through the format() function.通过format来设置其格式。

(1)The QSurfaceFormat class
  即表示QSurface的格式。The format includes the size of the color buffers, red, green, and blue; the size of the alpha buffer; the size of the depth and stencil buffers; and number of samples per pixel for multisampling. In addition, the format contains surface configuration parameters such as OpenGL profile and version for rendering, whether or not to enable stereo buffers, and swap behaviour.

  格式包括颜色缓冲的大小,rgb, 透明缓冲的大小。 深度缓存代销。 每个像素多采样的数量。 另外, 也包含surface配置参数,如Opengl的profile,以及版本来渲染。以及是否双缓存。等。

  默认的 QSurfaceFormat. 是Opengl 2.0版本,因为其提供了最高的跨平台移植性,以及Opengl的实现。

3. QOpenGLContext

 The QOpenGLContext class represents a native OpenGL context, enabling OpenGL rendering on a QSurface.

endl;

时间: 2024-08-26 08:44:49

QOpenGLFunctions的使用(2)的相关文章

QOpenGLFunctions的相关的使用(1)

QOpenGLFunctions的使用 1.  QOpenGLFunctions  说明  QOpenGLFunctions 类提供了跨平台的OpenGl ES2.0 API版本. OpenGL 2.0 提供了OpenGL中的子类集合,可以提供跨多个平台的桌面系统以及嵌入式OpenGL的实现.然而,却很难使用子类因为子类需要解决许多平台系统的操作问题. 因此 QOpenGLFunctions提供了这样的API,可以保证在所有的OpenGL系统中使用,并且也关注不同系统中的OpenGL的版本API

QOpenGLFunctions类

QOpenGLFunctions::QOpenGLFunctions() 1)构造一个默认的函数解析器. 2)在调用initializeOpenGLFunctions()函数来指定一个上下文前,该解析器无效. QOpenGLFunctions::QOpenGLFunctions(QOpenGLContext *context) 1)通过传递一个上下文来构造一个解析器. 2)如果该上下文为空,那么会为当前的QOpenGLContext创建一个解析器. 3)组中的上下文或组中其它上下文都必须时当前的

OpenGL ES 2兼容函数列表

关于OpenGL(含ES)的资料汗牛充栋,但是普遍存在的问题是,OES的资料不够系统,OGL的资料过于庞大 此列表详细记录了GLES2兼容函数的情况,使大家在学习时,对于算法和资料可以有针对性的选择 此列表来自Qt的QOpenGLFunctions类,该类用于创建OpenGL和OpenGL ES兼容项目(在一个工程里) 注:Qt支持各种版本的GL头文件导入,命名方式为QOpenGLFunctions_X_Y,对于更高级的3+桌面版,使用例如QOpenGLFunctions_3_0这种类 // G

尝试写第二个QOpenGLWidget程序 (未完成)

按照QGLWidegt的教程很有问题,因为两个完全不同了. 幸好搜到了官方的blog,http://blog.qt.io/blog/2014/09/10/qt-weekly-19-qopenglwidget/,文章前面就是说QOpenGLWidegt比QGLWidegt好,然后 (嵌入式就是es的,和desktop差不多的) Benefits for Desktop Of course, it is not just for OpenGL ES. On desktop platforms, Op

Qt5.6.0+OpenGL 纹理贴图首战告捷

重要的话写在前面~~通过今晚的实验,知道了EBO是不能随便release的~~~一直不要release就可以了,否则vao会失效 Display.h #ifndef DISPLAYWIDGET_H #define DISPLAYWIDGET_H #include <QGLWidget> #include <QOpenGLFunctions> #include <QOpenGLBuffer> #include <QOpenGLVertexArrayObject>

qt5_qml_Opengl_shader 第一弹----------------------openglunderqml的简化及介绍

最近得知opengl可以通过纹理贴图来渲染yuv的数据,这就免去了yuv-rgb,这个过程在arm上还是很耗时间的,于是就接触了opengl. 写这篇文章的目的是方便初学者使用qml来调用opengl显示,而qt自带的例程过于复杂,这里将之改成了一个简单的三角形的显示.(初学opengl,有错误请大家提出) 初学opengl,感觉不是很难,但是就是封装版本太多了,下边分三个来介绍: Glut: 用的最多,大致步骤如下 1>    初始化:glutInit(),opengl的初始化很复杂的,但是经

在之前的基础上继续分析openglwindow例子——了解视角

在写第二个QOpenGLWidget的时候,参考了openglwindow例子的顶点设置和颜色设置,及项目对象的使用.大致对整个过程有所了解了.第二个程序实现了绘制三角形并着色,但并没有像openglwindow那样做旋转展示,还是静态的. 现在来分析分析这个例子,学习视角. main.cpp #include "openglwindow.h" #include <QtGui/QGuiApplication> #include <QtGui/QMatrix4x4>

QtGUI Module&#39;s Classes

Qt GUI C++ Classes The Qt GUI module provides the basic enablers for graphical applications written with Qt. More... Reference Qt GUI C++ Classes Event Classes Painting Classes Rendering in 3D Event Classes These Qt Core classes are used to create an

基于Qt的OpenGL可编程管线学习(1)- 绘制一个三角形

0.写在前面的话 这里只是学习的时候做的笔记记录方便日后的查看,如果有大神看到觉得有问题的地方希望能给予指出,方便日后的学习,谢谢! 我是用的Qt版本为Qt5.6,开发环境为Qt Creator 1.QOpenGLWidget 在Qt开发环境下,使用OpenGL的可编程管线绘制一个三角形 效果如下图所示: 这里使用QOpenGLWidget进行绘制的,在QOpenGLWidget中需要重写 void initializeGL(void); void resizeGL(int w, int h);