Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 393
daj Avatar asked Mar 01 '14 18:03

daj


2 Answers

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.

like image 82
Jherico Avatar answered Oct 24 '22 04:10

Jherico


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

#ifdef __APPLE__
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
#endif
like image 42
frachop Avatar answered Oct 24 '22 04:10

frachop