痛苦面具:learnOpenGL系列,HelloWindow,主要是顺序问题

Posted Lemon-GPU

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了痛苦面具:learnOpenGL系列,HelloWindow,主要是顺序问题相关的知识,希望对你有一定的参考价值。

属于是非常困惑了,为啥初始化的顺序一定是这个样子:

  • 首先是include的东西,必须是先glad再是glfw,然后整个最基本的代码也得是按照一定的顺序来初始化
  • 首先是glfw的init,然后是创建窗口,然后是诡异的glfwMakeContextCurrent,然后是glfwSetFramebufferSizeCallback,然后才是去load这个gladloadGLLoader,这个参数又是个啥意思,这个renderloop居然还意外的好懂了。
  • 还有一个,glfw和glad到底是个啥啊

一个个来吧,哎
那第一个问题很好解决,原文都给了

Be sure to include GLAD before GLFW. The include file for GLAD includes the required OpenGL headers behind the scenes (like GL/gl.h) so be sure to include GLAD before other header files that require OpenGL (like GLFW).

来个deepl

请确保在GLFW之前包含GLAD。GLAD的include文件包括幕后所需的OpenGL头文件(如GL/gl.h),所以一定要在其他需要OpenGL的头文件(如GLFW)之前包括GLAD。

看了眼翻译还挺准确的
然后是第二个问题,这个啊,万能的StackOverflow已经给了:为啥我得用个OpenGL函数Loader

摘抄一下第一个答案:

OpenGL functions (core or extension) must be loaded at runtime, dynamically, whenever the function in question is not part of the platforms original OpenGL ABI (application binary interface).
For Windows the ABI covers is OpenGL-1.1
For Linux the ABI covers OpenGL-1.2 (there\'s no official OpenGL ABI for other *nixes, but they usually require OpenGL-1.2 as well)
For MacOS X the OpenGL version available and with it the ABI is defined by the OS version.
This leads to the following rules:
In Windows you\'re going to need a function loader for pretty much everything, except single textured, shaderless, fixed function drawing; it may be possible to load further functionality, but this is not a given.
In Linux you\'re going to need a function loader for pretty much everything, except basic multitextured with just the basic texenv modes, shaderless, fixed function drawing; it may be possible to load further functionality, but this is not a given.
In MacOS X you don\'t need a function loader at all, but the OpenGL features you can use are strictly determined by the OS version, either you have it, or you don\'t.
The difference between core OpenGL functions and extensions is, that core functions are found in the OpenGL specification, while extensions are functionality that may or may be not available in addition to what the OpenGL version available provides.
Both extensions and newer version core functions are loaded through the same mechanism.

deepl上

OpenGL函数(核心或扩展)必须在运行时动态加载,只要该函数不属于平台的原始OpenGL ABI(应用程序二进制接口)。
对于Windows来说,ABI包括OpenGL-1.1。
对于Linux,ABI包括OpenGL-1.2(其他*nixes没有官方的OpenGL ABI,但它们通常也需要OpenGL-1.2)。
对于MacOS X来说,可用的OpenGL版本和ABI是由操作系统版本定义的。
这就导致了以下的规则。
在Windows中,除了单一纹理的、无着色器的、固定功能的绘图,你需要一个函数加载器来实现几乎所有的功能;也许有可能加载更多的功能,但这并不是必然。
在Linux中,除了基本的多纹理和基本的texenv模式,无着色器,固定功能的绘制,你需要一个函数加载器来实现几乎所有的功能;也许可以加载更多的功能,但这并不是必然。
在MacOS X中,你根本不需要函数加载器,但你可以使用的OpenGL功能是由操作系统版本严格决定的,要么你有,要么你没有。
OpenGL核心功能和扩展功能的区别在于,核心功能可以在OpenGL规范中找到,而扩展功能是在现有的OpenGL版本提供的功能之外,可能有也可能没有。
扩展和较新版本的核心功能都是通过相同的机制加载的。

自己改了点用语。不过还是没解决。Loader到底是啥?
我推荐点东西好了,看完也就就差不多了

这样就把第二第三解决了。

以上是关于痛苦面具:learnOpenGL系列,HelloWindow,主要是顺序问题的主要内容,如果未能解决你的问题,请参考以下文章

LearnOpenGL 笔记 - 入门 04 你好,三角形

LearnOpenGL 笔记 - 入门 01 OpenGL

LearnOpenGL - Android OpenGL ES 3.0 绘制三角形

LearnOpenGL 笔记 - 入门 03 你好,窗口

LearnOpenGL学习笔记——可用GitHub下载本项目啦~

OpenGL - 如何理解 VAO 与 VBO 之间的关系