简体   繁体   中英

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.

I've already run some tutorials that draw lines/triangles etc. I then started trying the more modern tutorials at www.open.gl

I'm running into trouble with the OpenGL 3+ API. I already include gl3.h in my headers:

#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 . 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);

I believe I've seen this problem myself. I had to add an ifdef statement in one of my headers

#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. However, if you want to use the SDL OpenGL header, you should problaby do it like this

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

or you'll only get the older OpenGL 1.x functions.

You don't have to include SDL_opengl.h , just include :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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