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。编译运行,完成一个最简单的例子。

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经常用到的函数被删除了。

多谢,亲爱的美美。

猜你喜欢

转载自blog.csdn.net/islinyoubiao/article/details/113765344