简体   繁体   English

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

[英]use of undeclared identifier 'glGenVertexArrays' error even after including OpenGL/gl3.h in OSX 10.8.5

I'm opening an OpenGL context using SDL in OSX 10.8.5. 我在OSX 10.8.5中使用SDL打开OpenGL上下文。

I've already run some tutorials that draw lines/triangles etc. I then started trying the more modern tutorials at www.open.gl 我已经运行了一些绘制线条/三角形的教程等。然后我开始在www.open.gl上尝试更现代的教程

I'm running into trouble with the OpenGL 3+ API. 我遇到了OpenGL 3+ API的问题。 I already include gl3.h in my headers: 我已在头文件中包含gl3.h:

#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <OpenGL/gl3.h>

I get a warning, which is expected since I think the sdl headers open gl.h . 我得到一个警告,这是预期的,因为我认为sdl标题打开gl.h That's okay, but the problem is that the but the compiler still reports that glGenVertexArrays as undefined even though gl3.h is included, saying error: use of undeclared identifier 'glGenVertexArrays' glGenVertexArrays(1, &vao); 这没关系,但问题是但是编译器仍然报告glGenVertexArrays为undefined,即使包含了glGenVertexArrays ,也就是说error: use of undeclared identifier 'glGenVertexArrays' glGenVertexArrays(1, &vao);

I believe I've seen this problem myself. 我相信我自己也见过这个问题。 I had to add an ifdef statement in one of my headers 我必须在我的一个标题中添加一个ifdef语句

#ifdef __APPLE__
#define glGenVertexArrays glGenVertexArraysAPPLE
#define glBindVertexArray glBindVertexArrayAPPLE
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE
#endif

Also, you should be including either the SDL OpenGL header or the native system header. 此外,您还应该包括 SDL OpenGL头或本机系统头。 However, if you want to use the SDL OpenGL header, you should problaby do it like this 但是,如果你想使用SDL OpenGL标题,你应该像这样做

#define GL_GLEXT_PROTOTYPES 1
#include <SDL2/SDL_opengl.h>

or you'll only get the older OpenGL 1.x functions. 或者你只会获得较旧的OpenGL 1.x功能。

You don't have to include SDL_opengl.h , just include : 您不必包含SDL_opengl.h ,只需包括:

#ifdef __APPLE__
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
#endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM