什么是OpenGL

OpenGL is mainly considered an API (an Application Programming Interface) that provides us with a large set of functions that we can use to manipulate graphics and images. However, OpenGL by itself is not an API, but merely a specification

Windows 系统自带 OpenGL 1.1,但要用 OpenGL 现代接口(如 3.3+),需要从驱动中获取,所以需要额外的库来获取扩展函数。

OpenGL 3.3 是什么

OpenGL 3.3 是 2010 年发布的版本,是 OpenGL Core Profile 系列的一部分,新增了大量的环境配置、VBO/VAO 等新接口,也弃用了这些 Fixed Function Pipeline API

这些接口 是被加入 OpenGL API 规范的,但实际就是显卡驱动内部实现

程序怎么调用这些 glXXX()

在 Windows 系统中,系统自带的 opengl32.lib 只支持到 OpenGL 1.1,而无法直接调用 3.3 新增出的函数。

所以我们需要一个方式去 在运行时查找驱动里的函数地址,这就是 GLEW / GLAD 这类 扩展函数加载器 的作用

GLEW / GLAD 的作用是什么

PFNGLGENVERTEXARRAYSPROC glGenVertexArrays =
    (PFNGLGENVERTEXARRAYSPROC)wglGetProcAddress("glGenVertexArrays");

然后你就能像常规那样用了:

glGenVertexArrays(1, &vao);

类似地,GLAD 是新一代自动生成代码的工具。