QT中使用OpenGL function

1.前言

QT做界面编程很方便,QT+OpenGL的使用也很方便,因为QT对原生的OpenGL API进行了面向对象化的封装。

如:

cpp 复制代码
函数:initializeOpenGLFunctions()......
类:QOpenGLVertexArrayObject、QOpenGLBuffer、QOpenGLShaderProgram......
数学工具类:QVector3D、QMatrix4x4......

有些时候我们需要使用原生的OpenGL API,这在QT中也很方便,该怎么做呢?

2.内容

如果想在QT中使用原生的OpenGL API,如**glReadPixels** 、glShaderSource,需要参考QT官方文档说明:

QOpenGLFunctions Class | Qt GUI 6.8.1

继承类QOpenGLExtraFunctions,然后就可以使用上述原生API了,常用的用法是这样的,

cpp 复制代码
#include <QOpenGLWidget>
#include <QOpenGLFunctions_4_5_Core>
#include <QOpenGLShaderProgram>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>

//#include <AIS_InteractiveContext.hxx>

class QMenu;
class QRubberBand;

//! Adapted a QWidget for OpenCASCADE viewer.
class OccView : public QOpenGLWidget, QOpenGLFunctions_4_5_Core
{
   // implementation here

}
相关推荐
ShineWinsu14 小时前
对于Qt:事件分发器以及事件过滤器的解析
c++·qt·面试·gui·客户端·事件过滤器·事件分发器
ShineWinsu1 天前
对于Qt:事件的解析
c++·qt·面试·笔试·gui·客户端·事件
西西弗Sisyphus2 天前
Qt QML 程序是怎么跑起来的(1)qml-only
开发语言·c++·qt
小灰灰搞电子2 天前
QAccel 类讲解与代码示例:Qt 3 中的键盘加速键管理
qt·计算机外设
万有AI3 天前
FastAPI中间件复盘:注册顺序换算、限流分层与SSE直通的三个设计决策
ai·api
JonaHu3 天前
AceDataCloud Coding Plan 多模型编程:从 Chat Completions 迁移到 Responses API 与工具调用
python·大模型·api·ai编程·acedatacloud
用户298698530143 天前
使用 Python 提取 Word 文档中的文本与图片
后端·python·api
ShineWinsu3 天前
对于Qt:重写事件步骤的解析
开发语言·c++·qt·客户端·事件·鼠标事件·步骤
敲上瘾4 天前
Qt控件通用属性:geometry、qrc资源到QSS样式表等
开发语言·c++·qt·ui
ShineWinsu4 天前
对于Qt:QFontDialog的解析
c++·qt·面试·gui·字体·客户端·qfontdialog