I have spent the day struggling to get my simple engine to work on Mac. I have SDL working and now the only thing giving trouble is opengl. The engine uses modern opengl (shader based) and so requires GLEW. I have tried everything from fink to MacPorts to install it and nothing works.
The most success I have had has been building it from source. First I got an error saying 'GL/glu.h' no such file or directory found.
So I renamed the includes to OpenGL/glu.h
and that fixed that issue. But now I get this error ld: unknown option: -shared
I am completely stuck at this point.
Also Id rather a static build if anyone knows how to do that.
You can use Homebrew to do the work for you:
brew install glew
The engine uses modern opengl (shader based) and so requires GLEW
GLEW is not a prerequisite for using modern OpenGL features. It is a method to load extended functionality, not the only one. You're on MacOS X so, the extension system is of little use for you anyway, because the OpenGL version supported is entirely determined by the OS and the available framework. Apple develops the OpenGL drivers themself and the extensions they provide are only those, that are for features not found in the OpenGL specification (i.e. vendor specific and EXT). All you need is a version of the OpenGL Framework new enough. Any MacOS X released after 2006 can do it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With