第一个QGLViewer程序
生活随笔
收集整理的這篇文章主要介紹了
第一个QGLViewer程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
環境:vs2017 + qt5.11 + QGLViewer2.7.1
1、新建QtGUIApplication
新建一個QtGUIApplication(勾上opengl或者自己配置opengl32.lib,glu32.lib)
2、?配置QGLViewer
配置QGLViewer(包含目錄、庫目錄、附加依賴項)
release模式QGLViewer2.lib(release模式QGLViewerd2.lib)?
3、加入QGLViewer窗口
ui文件(Form Files/mainwindow.ui)
?文件中填上頭文件,運行報錯
缺少XML module,Qt Project Settings->Qt Modules
?
?ok,跑起來了
4、繪制圖像
頭文件mainwindow.h中添加:
protected Q_SLOTS:void draw();?mainwindow.cpp文件中添加:
void MainWindow::draw() {//官方圖像鎮樓// Draws a spiralconst float nbSteps = 200.0;glBegin(GL_QUAD_STRIP);for (float i = 0; i < nbSteps; ++i) {float ratio = i / nbSteps;float angle = 21.0 * ratio;float c = cos(angle);float s = sin(angle);float r1 = 1.0 - 0.8 * ratio;float r2 = 0.8 - 0.8 * ratio;float alt = ratio - 0.5;const float nor = .5;const float up = sqrt(1.0 - nor * nor);glColor3f(1.0 - ratio, 0.2f, ratio);glNormal3f(nor * c, up, nor * s);glVertex3f(r1 * c, alt, r1 * s);glVertex3f(r2 * c, alt + 0.05, r2 * s);}glEnd(); }初始化時連接viewer和draw函數:
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) {ui.setupUi(this);connect(ui.viewer, SIGNAL(drawNeeded()), this, SLOT(draw())); }運行(官方圖鎮樓)
源碼:
總結
以上是生活随笔為你收集整理的第一个QGLViewer程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 漫画: 可以给女朋友讲解 Linux 内
- 下一篇: 企业级低代码平台,Jeecgboot-V