0

I've recently bought a mac to do some cross-platform development and I've got some problems with OpenGL.

Use of undeclared identifier 'glBindVertexArray'

I'm using glfw3 (glfw3.h) with glew (glew.h) and this is how i have it included in code:

#ifdef WIN_32
#include <glew.h>
#endif
#ifdef __APPLE__
#include <gl/glew.h>
#endif

#define GLEW_STATIC

#define GLFW_INCLUDE_GLCOREARB

#include "glfw3.h"

Any obvious errors as to why I'm getting these undefined identifiers?

genpfault
  • 51,148
  • 11
  • 85
  • 139
rocklobster
  • 609
  • 2
  • 10
  • 23
  • There's no need for GLEW on OS X. It has all the headers and libraries for the supported OpenGL versions. Does it work if you simply remove the include of ``? – Reto Koradi Jul 13 '14 at 19:00
  • Sorry for the late reply. Unfortunately no it doesn't work after removing GLEW. Good to know it's not needed though. – rocklobster Jul 13 '14 at 20:40
  • Weird. This just came up a few days ago: http://stackoverflow.com/questions/24664722/c-code-using-glfw3-on-maverick-glshadersource-no-matching-function/. For that poster, it worked after adding the `GLFW_INCLUDE_COREARB` define. – Reto Koradi Jul 13 '14 at 20:57
  • Ah, do I need to put GLFW_INCLUDE_GLCOREARB in front of EVERY include of glfw3? Or just the first one? – rocklobster Jul 13 '14 at 21:33
  • Hmm that seemed to solve it, does that sound about right? – rocklobster Jul 13 '14 at 22:08
  • Yes, if you include the glfw3 headers in multiple source files, you'll need the define every time. What I typically do when writing cross platform code, is to define my own header file (e.g. named `gl_headers.h`) that conditionally includes the platform specific GL headers. Then I only include my own header in the rest of the code, and the platform dependency of the needed include files is isolated in a single place. – Reto Koradi Jul 13 '14 at 22:19
  • Great idea, If you want to post that as an answer I'll be happy to accept it. – rocklobster Jul 14 '14 at 05:56

2 Answers2

0

You don't need GLEW on OS X. All supported OpenGL functions are declared in header files that are included with the standard development environment. If you want to see what header files are present, and what they contain, the exact location of the header files is explained in this answer: Where are the OpenGL header files located on MacOSX?. You don't normally have to worry about the path name, the compiler will find the right one automatically if you include it with a name like <OpenGL/gl3.h>.

For GLFW, you had the right include sequence in your question:

#define GLFW_INCLUDE_GLCOREARB
#include <GLFW/glfw3.h>

What you were missing based on the discussion in the comments is that you need the GLFW_INCLUDE_GLCOREARB define every time before you include <GLFW/glfw3.h>.

When you develop cross platform code, needing conditional includes for each platform in every source file that contains OpenGL calls is cumbersome to maintain. A simple approach to make life easier is to keep the system dependent includes in a single header, and then include that header in your source files. This isolates the system dependencies, and will make it much easier to for example add a platform later.

For example, you could define a header named gl_includes.h, which includes the system dependent OpenGL includes, like you have it in your code:

#ifdef WIN32
#include ...
#endif

#ifdef ...
#include ...
#endif

Then, in all your source files, you only include this header:

#include "gl_includes.h"
Community
  • 1
  • 1
Reto Koradi
  • 53,228
  • 8
  • 93
  • 133
0

If you are using CC=clang++, add -isysroot to your argument

Example, in my makefile:

CC=clang++
CFLAGS:= -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
Dat
  • 5,405
  • 2
  • 31
  • 32