gpt4 book ai didi

c++ - 最新的 OpenGL 应用程序是否必须使用 GLEW?

转载 作者:可可西里 更新时间:2023-11-01 15:05:46 24 4
gpt4 key购买 nike

我一直在阅读我的 Visual Studio 版本中包含的 gl.h 头文件,它似乎已经过时了。

我不希望 GLUT 或介于两者之间的任何其他中间件/实用程序库为我做肮脏的工作,包括 GLEW。有人可以详细说明为什么以及如何获取/查询 4.0 规范的现代功能集以及 ​​GLEW 背后的一般想法是什么吗?

最佳答案

MSVC++ 附带的 gl.h 仅包含 Windows 附带的 opengl32.dll 导出的函数。这个 DLL 主要只是一个所谓的“蹦床”到实际驱动程序中。但它只导出一个非常旧的 OpenGL 版本,即 OpenGL-1.1。

除此之外的任何功能都必须通过扩展机制访问。

I do not want GLUT or any other middleware/utility library in between to do the dirty work for me, that includes GLEW.

GLUT 与 GLEW 完全无关

Could someone elaborate on why and how does one acquire/query for the modern feature set of the 4.0 specification and what's the idea behind GLEW in general?

您通过已经提到的扩展系统获得现代功能集。

有一个函数 ?glGetProcAddress(具体名称取决于操作系统环境,在 Windows wglGetProcAddress 中)。使用此函数,您可以检索指向扩展过程的函数指针当前 OpenGL 上下文(在 GLX 中,函数指针对于所有上下文都是相同的,但在 Windows 中它们可能不同)。

加载一个扩展是这样的:

typedef (*OGLEXTP_SOMEEXTENSIONFUNCTION)(...)
OGLEXTP_SOMEEXTENSIONFUNCTION oglextp_glSomeExtensionFunction = NULL;
#define glSomeExtensionFunction oglextp_glSomeExtensionFunction;


struct Extensions
{
bool SomeExtensionFunction;
}

errorcode initGLExtensions(){
Extensions available;

GLubyte extensions = glGetStrings(GL_EXTENSIONS);
parse_extension_string(extensions, available);

if( available.SomeExtensionFunction ) {
oglextp_glSomeExtensionFunction = wglGwtProcAddress("glSomeExtensionFunction");
if( !oglextp_glSomeExtensionFunction )
return errorcode;
}
}

而且您必须为每个函数编写大量代码。没有人愿意写这个。因此 GLEW 的开发人员想出了一组脚本,从 opengl.org 获取扩展规范并自动创建整个扩展加载并将其包装到一个小库中,这不会创建额外的依赖项。

如果您想使用更高的 OpenGL 功能:使用 GLEW。不是因为它是强制性的,而是因为它是解决此问题的最直接方法。

关于c++ - 最新的 OpenGL 应用程序是否必须使用 GLEW?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10670555/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com