天天看點

OpenGL在Qt5中應用入門

OpenGL圖形引擎對于程式員來講好重要,它給予了非常強大的顯示表達能力。

https://baike.baidu.com/item/OpenGL/238984?fr=aladdin

在Qt5中使用OpenGL渲染也比較友善。

1。首先在.pro檔案中添加 opengl

QT       += core gui svg opengl
           

2。在.pro中添加lib

LIBS += -lopengl32 -lglu32
           

3。添加頭檔案

#include <QtOpenGL>
           

4。寫一個最簡單的代碼

#include "mainwindow.h"
#include <QApplication>

#include <QtOpenGL>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    //MainWindow w;
    //w.show();
    QOpenGLWindow window;
    window.setTitle("Hello World! OpenGL and Qt5");
    window.resize(640, 480);
    window.show();

    return a.exec();
}
           

5。編譯運作,完成一個最簡單的例子。

OpenGL在Qt5中應用入門
In 2008, Khronos Group, the company that maintains and develops OpenGL, announced the release of the OpenGL 3.0 specification, which created a huge uproar and controversy throughout the industry.

由于OpenGL3.0和舊版本的OpenGL存在較大的差異,是以要注意開發時候的選擇。

In this chapter, we will use the newer OpenGL 3 instead of the older, deprecated OpenGL 2. The coding style and syntax are very different between this two versions, which makes the switch over very troublesome. However, the performance improvement will make it worth the time switching over to OpenGL 3.

是以,文章用到的是OpenGL3.0,請讀者注意。

Common OpenGL functions such as glBegin, glVertex2f, glColor3f, glMatrixMode, and glLoadIdentity have all been removed from OpenGL 3.

真的要注意,在舊版本的OpenGL經常用到的函數被删除了。

多謝,親愛的美美。

繼續閱讀