我在 OSX 10.8.5 中使用 SDL 打开 OpenGL 上下文。
我已经运行了一些绘制线条/三角形等的教程。然后我开始在 www.open.gl 上尝试更现代的教程
我在使用 OpenGL 3+ API 时遇到了问题。我已经在标题中包含了 gl3.h:
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <OpenGL/gl3.h>
我收到警告,这是预料之中的,因为我认为 sdl header 打开 gl.h
。没关系,但问题是编译器仍然报告 glGenVertexArrays
为未定义,即使包含 gl3.h,说 error: use of undeclared identifier 'glGenVertexArrays' glGenVertexArrays(1, &vao);
最佳答案
我相信我自己也遇到过这个问题。我不得不在我的一个标题中添加一个 ifdef 语句
#ifdef __APPLE__
#define glGenVertexArrays glGenVertexArraysAPPLE
#define glBindVertexArray glBindVertexArrayAPPLE
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE
#endif
此外,您应该包括 SDL OpenGL header 或 native 系统 header 。但是,如果您想使用 SDL OpenGL header ,您可能应该这样做
#define GL_GLEXT_PROTOTYPES 1
#include <SDL2/SDL_opengl.h>
否则您将只能获得较旧的 OpenGL 1.x 函数。
关于c++ - 使用未声明的标识符 'glGenVertexArrays' 错误,即使在 OSX 10.8.5 中包含 OpenGL/gl3.h 之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22118518/