Qt--openGL
来源:互联网 发布:天行网络加速器 编辑:程序博客网 时间:2024/05/23 13:39
实现第一个Qt的opengl窗口
效果图:
源码实现:
在工程文件中添加QT += opengl
**
- mainwindow.h
**
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QOpenGLWindow>#include <QOpenGLFunctions> //继承QOpenGLWindow或QOpenGLWidget and //QOpenGLFunctionsclass MainWindow : public QOpenGLWindow,protected QOpenGLFunctions{ Q_OBJECTpublic: ~MainWindow(); //重写QOpenGLWindow的下面三个函数 void initializeGL(); //初始化void resizeGL(int width, int height);//绘制窗口大小 void paintGL();//重新绘制窗口图像private: void printContextInformation();//获取调试信息};#endif // MAINWINDOW_H
**
2.mainwindow.cpp
**
#include "mainwindow.h"#include <QDebug>MainWindow::~MainWindow(){}void MainWindow::initializeGL(){ initializeOpenGLFunctions(); printContextInformation(); glClearColor(0.0f,0.0f,1.0f,1.0f);//设置颜色}void MainWindow::resizeGL(int width, int height){ //未作处理}void MainWindow::paintGL(){ glClear(GL_COLOR_BUFFER_BIT);}// 打印相关信息,调试用void MainWindow::printContextInformation()\{ QString glType; QString glVersion; QString glProfile; glType = (context()->isOpenGLES())?"OpenGL ES":"OpenGL"; glVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION));#define CASE(c) case QSurfaceFormat::c: glProfile = #c; break switch (format().profile()) { CASE(NoProfile); CASE(CoreProfile); CASE(CompatibilityProfile); //?? }#undef CASEqDebug() << qPrintable(glType) << qPrintable(glVersion)<< "(" << qPrintable(glProfile) << ")";}
**
- main.cpp
**
#include "mainwindow.h"#include <QApplication>#include <QGLFormat>int main(int argc, char *argv[]){ QApplication a(argc, argv); // 设置 OpenGL 信息 // 注意:必须在show()之前设置信息// QSurfaceFormat format;// format.setRenderableType(QSurfaceFormat::OpenGL);// format.setProfile(QSurfaceFormat::CoreProfile);// format.setVersion(3,3); MainWindow w; // w.setFormat(format); w.resize(QSize(800, 600)); w.show(); return a.exec();}
0 0
- QT+openGL
- QT + OpenGL
- Qt--openGL
- QT+OpenGL
- Qt OpenGL----创建openGL窗口
- Qt:VS&QT 配置OpenGL
- OpenGL in QT
- Qt里的OpenGL
- OpenGL in Qt
- Qt OpenGL教程
- QT中编译OpenGL
- Qt OpenGL三维绘图
- QT+OpenCV+OpenGL
- QT openGL 编程 笔记
- Qt下OpenGL框架
- Qt 与 OpenGL ES
- QT openGL 编程 笔记
- Qt: OpenGL模板
- Octave/Matlab中.*(./)和*(/)的区别
- 正则校验Java和js代码
- APP支持文件共享设置(iOS)
- 安卓屏幕适配
- MCMC(Markov Chain Monte Carlo)的理解与实践(Python)
- Qt--openGL
- JSP的入门简介
- svn 冲突
- Java经典算法
- 虚拟IP原理
- galang 学习之grpc+ protobuf(二)
- 基本TCP套接字编程
- 仿微信朋友圈日期显示 时间戳格式化
- Compound Words UVA