windows glGenBuffers 为 NULL,在使用 glew 时出现 0x0000000 访问冲突

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5021956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:12:00  来源:igfitidea点击:

glGenBuffers is NULL giving a 0x0000000 access violation when using glew

windowsopenglaccess-violation

提问by Mark Watt

> I have visual studio c++ express and a NVIDIA GeForce 7900 GS. I'm using glew to get at the openGL extensions. Calling glGenBuffers crashes as its a NULL pointer tho. I have an open GL context before I make the call ( wglGetCurrentContext() != NULL ). I'm calling glewInit() before the call. glewGetString( GLEW_VERSION ) is returning GLEW_VERSION_1_5. What am I doing wrong ? Is the card too old ? Is it the driver ?

> 我有 Visual Studio C++ express 和 NVIDIA GeForce 7900 GS。我正在使用 glew 来获取 openGL 扩展。调用 glGenBuffers 会崩溃,因为它是一个 NULL 指针。在我拨打电话之前,我有一个开放的 GL 上下文( wglGetCurrentContext() != NULL )。我在调用之前调用了glewInit()。glewGetString( GLEW_VERSION ) 正在返回 GLEW_VERSION_1_5。我究竟做错了什么 ?卡是不是太旧了?是司机吗?

回答by Cacho Santa

Remember to make a glewInit()call in your code so that you get valid pointers to GL functions.

请记住glewInit()在您的代码中进行调用,以便您获得指向 GL 函数的有效指针。

Hope it helps.

希望能帮助到你。

回答by James

Without seeing your code it would be difficult to tell, but what you are attempting to do seems like it could be helped a lot by using GLee. It is designed to load all current extensions and you have the ability to check what is supported, e.g. :

如果没有看到您的代码,很难判断,但是您尝试做的事情似乎可以通过使用GLee来获得很大帮助。它旨在加载所有当前扩展,您可以检查支持的内容,例如:

#include <gl\GLee.h>          // (no need to link to gl.h) 

...

if (GLEE_ARB_multitexture)    //is multitexture support available?
{
  glMultiTexCoord2fARB(...);  //safe to use multitexture
}
else
{
 //fallback
}

The above was shamelessly copy/pasted from the GLee site, but it displays the functionality I'm trying to showcase.

以上内容是从GLee 站点无耻地复制/粘贴的,但它显示了我试图展示的功能。

回答by TheBuzzSaw

I have actually run into this problem with GLEW. For me, it was nullifying the function pointer for glGenerateMipmap. I fixed it by simply restoring the pointer to the appropriate function. This is my example in Linux:

我实际上遇到了 GLEW 的这个问题。对我来说,它使 glGenerateMipmap 的函数指针无效。我通过简单地将指针恢复到适当的函数来修复它。这是我在 Linux 中的示例:

glGenerateMipmap = (void(*)(GLenum))
    glXGetProcAddressARB((GLubyte*)"glGenerateMipmap");

There is a WGL equivalent for glXGetProcAddress; I just don't remember the name off the top of my head. Try manually restoring the functions using this method. If you come across manyfunctions that are null, something is definitely wrong in your setup process. The only other functions I recall having to restore were glGenVertexArrays, glBindVertexArray, and glDeleteVertexArrays. If your glGenBuffers is null, odds are that glBindBuffer and glDeleteBuffers are null as well. :(

glXGetProcAddress 有一个 WGL 等效项;我只是不记得我头顶上的名字。尝试使用此方法手动恢复功能。如果您遇到许多为 null 的函数,则说明您的设置过程肯定有问题。我记得唯一需要恢复的其他函数是 glGenVertexArrays、glBindVertexArray 和 glDeleteVertexArrays。如果您的 glGenBuffers 为空,则 glBindBuffer 和 glDeleteBuffers 也很可能为空。:(

回答by datenwolf

Test if the desired extension is actually supported by checking the string returned by glGetString(GL_EXTENSIONS); if it's not there you know what's causing your problems.

通过检查 glGetString(GL_EXTENSIONS) 返回的字符串来测试是否实际支持所需的扩展名;如果它不存在,您就会知道是什么导致了您的问题。

回答by grenangen

You need to call glewInit() post having a valid context. And that would be, in the world of glew, after you've called glfwMakeContextCurrent(myWindow);

您需要调用具有有效上下文的 glewInit() 帖子。这将是,在 glew 的世界中,在您调用 glfwMakeContextCurrent(myWindow); 之后;