c++ - 使用未声明的标识符 'glGenVertexArrays' 错误,即使在 OSX 10.8.5 中包含 OpenGL/gl3.h 之后

标签 c++ macos opengl sdl

我在 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/

相关文章:

c++ - 程序将无法在 Visual Studio 之外正常运行

c++ - GLEW 链接错误。错误 LNK2019

opengl - 如何从模型 View 矩阵中获取相机旋转矩阵

c++ - 预分配 vector 是否更有效?

python - 我正在尝试使用 brew 安装 postgresql,但找不到 Python.h

java - 在 MAC 上升级到 JDK 8 后出错

c++ - 在Mac上编译FLTK程序

c++ - openGL 中带有/对象的静态背景。 "bake"的最佳方式?

opengl - 处理中几何着色器的意外行为

c++ - 如何分析 Lambda 函数性能?