Including headers in your apps - yes or no?


I am beginning OpenGL coding, and I see many projects including GL headers within their distributables. Is this good practice or an antipattern? Pardon the noob question, but I am rather new at graphics programming (although I find it amazing!)


Your going to get different answers on this, but in my experience this is a good idea. If you don’t, your app just won’t build on some platforms (e.g. old GL includes don’t define everything you can use in your app). If you do, then your app will always compile because your headers define/support everything in GL that you reference in your code – independent of what old GL includes/libs might be installed on the system.

And if you dynamically load in the function pointers you need rather than just assuming they are there, then you can link and run on pretty much any OpenGL libraries that meet your base version requirements.

Besides, the OpenGL headers are standard (see The OpenGL Registry for the latest versions); platforms shouldn’t be monkeying with their contents.

When you say “within their distributables”, do you mean source distributions, libraries, or something else? Because there’s no point in shipping header files for binary-only applications.

If you mean in source code, yes, that’s standard practice. Generally, OpenGL loading libraries are used in OpenGL applications; these come with their own headers. Even those that don’t use a library will have to use the headers on the OpenGL registry page. Those headers change with each OpenGL version, so it’s best to not try to rely on some global copy, for fear that it doesn’t have what your application needs.