Take a look at /System/Library/Frameworks/OpenGL.framework/Headers/gl.h
, you should see a pretty standard include guard on the first line: #ifndef __gl_h_
. If you look at gl3.h
you will notice an equally standard include guard for __gl3_h_
. This warning is only triggered when both are defined and GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
is undefined.
The easiest way to prevent including anything from within gl.h
would be to #define __gl_h_
before it is ever included. To avoid messing up your actual code with something nasty like:
#ifdef __APPLE__
# define __gl_h_
# define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
#endif
I would suggest adding -D__gl_h_ -DGL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
as a compiler switch to your Makefile when you target OS X (so that no matter where gl.h
is indirectly included from, it never does anything). This really is not the right way to go about tackling this, and that warning was generated for a reason (which you pointed out in your question -- deprecated OpenGL tokens will not generate compiler warnings / errors when both headers are included).
I think SDL2 itself ought to have some pre-processor mechanism to do what I did above with #ifdef __APPLE__
but in lieu of that, this will get the job done. It is not an error by any means to include both, OS X just provides a handy mechanism to generate compiler errors when deprecated tokens (e.g. GL_MODELVIEW
) are used in a project that is supposed to be core 3+.
On other platforms whether you are using core OpenGL 3+ is not so black and white at compile-time, so the compiler cannot be used for this purpose. It is one of those things that Apple does just because they can; "think different."