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

}
相关推荐
axban21 小时前
QT M/V架构开发实战:M/V架构的初步认识
开发语言·数据库·qt
大可门耳1 天前
Qt的数据库模块介绍,Qt访问SQLite详细示例
数据库·qt·sqlite
onelafite1 天前
小红书笔记评论一键获取,实时查看作品数据
api·fastapi
axban1 天前
QT M/V架构开发实战:QAbstractItemModel介绍
java·数据库·qt
草丛中的蝈蝈1 天前
qt中给QListWidget添加上下文菜单(快捷菜单)
开发语言·qt
大可门耳1 天前
qt调用cef的Demo,实现js与C++之间的交互细节
javascript·c++·经验分享·qt
佛珠散了一地1 天前
【qt】通过TCP传输json,json里包含图像
qt·tcp/ip·json
芝士小宇1 天前
2025.9.12Qtday2
c++·qt
dllmayday1 天前
FontForge 手工扩展 iconfont.ttf
css·qt
码农客栈1 天前
qt QAreaLegendMarker详解
qt