Update 20180912 - don't use GLEW. It's just not worth the trouble...
I've installed GLEW using from source using:
make GLEW_DEST="$HOME/local" OPT="-march=core2 -O2" install.all
Your optimizations and destinations may vary. This yields a libGLEW.a, libGLEWmx.a, and their dylib counterparts in $HOME/local/lib
. The pkgconfig
sub-directory will also include glew.pc
. GLEW doesn't always play well with others either. Having to set globals like glewExperimental
, as well as needing to be careful with the order of inclusion of other headers: <OpenGL/gl3.h>
or <glfw.h>
, etc.
If I can offer some advice - forget SDL for modern GL programming. If you want to get into pure, modern GL on OS X . - consider something like:
#if defined (__APPLE_CC__)
#include <OpenGL/gl3.h>
#else
#include <GL/gl3.h> /* assert OpenGL 3.2 core profile available. */
#endif
#define GLFW_INCLUDE_GL3 /* don't drag in legacy GL headers. */
#define GLFW_NO_GLU /* don't drag in the old GLU lib - unless you must. */
#include <GL/glfw.h> /* simple and easy to use. omit legacy GL. */
Installing GLFW is pretty easy too:
> env PREFIX="$HOME/local" CFLAGS="-march=core2 -O2" make cocoa cocoa-dist-install
Again, your settings may differ.
20160412: My comments about SDL are out of date, as others have pointed out. Particularly if you're working on yet-another-engine. I maintain that glfw3 is an easier way to make modern OpenGL apps on OSX. It's very well written and maintained code, with a (correctly!) narrow focus on GL and event handling. Obviously, from an 'engine' perspective, SDL2 is providing portable extended video APIs, audio APIs, thread APIs, etc. Though with C11 and C++11, even a thread API abstraction layer is perhaps redundant.
GLEW is problematic in that in can't handle multiple contexts without extensive user intervention. This isn't an issue for OSX, which provides a core profile API and doesn't need to load 'function points'. IIRC, GL on X (DRI?) has this too - but I might be wrong about that. There are other loaders out there. I'm still waiting for one to rule them all, which ensures different functions pointers are loaded for multiple contexts if necessary, and uses a thread-local (or even a pthread key) for correct dispatch, that can be generated from the latest gl.xml from Khronos, or whoever...
20180912
I think the easiest approach right now is using GLFW to provide a context, and use GLAD to resolve GL function pointers. The only downside is that there's no effective management of multiple GL contexts. This is what GLFW is currently using in its demos... I would forget about GLEW completely at this point.
sudo port install glew
give as an error? – Minor