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

时间:2021-09-17 14:40:27   收藏:0   阅读:32

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

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

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到底是啥?
我推荐点东西好了,看完也就就差不多了

这样就把第二第三解决了。说的详细点,其实就是glfw是关注整个渲染流程里面比较外围的东西,渲染和显示解耦合了(个人认为),glad就是reload的函数指针,把driver的东西封装抽象了。
其实还是很蒙蔽。

冒着被舍友打屎的风险,我继续来bb了
关键的函数其实是glfwMakeContextCurrent,只有让window在当前这个程序所在的进程之后,我们才能load一下函数指针什么的,剩下的就是设置状态转移而已。你可以试一下让load在current之前,会失败。这个函数本身应该还有点side-effect的。

This function makes the OpenGL or OpenGL ES context of the specified window current on the calling thread. A context must only be made current on a single thread at a time and each thread can have only a single current context at a time.
When moving a context between threads, you must make it non-current on the old thread before making it current on the new one.
By default, making a context non-current implicitly forces a pipeline flush. On machines that support GL_KHR_context_flush_control, you can control whether a context performs this flush by setting the GLFW_CONTEXT_RELEASE_BEHAVIOR hint.
The specified window must have an OpenGL or OpenGL ES context. Specifying a window without a context will generate a GLFW_NO_WINDOW_CONTEXT error.

原文:https://www.cnblogs.com/Lemon-GPU/p/15302825.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!