[c++] How to get the GL library/headers?

#include <gl\gl.h> 
#include <gl\glu.h> 
#include <gl\glaux.h>

This is an example, but where to get GL headers?

This question is related to c++ opengl

The answer is


Windows

On Windows you need to include the gl.h header for OpenGL 1.1 support and link against OpenGL32.lib. Both are a part of the Windows SDK. In addition, you might want the following headers which you can get from http://www.opengl.org/registry .

  • <GL/glext.h> - OpenGL 1.2 and above compatibility profile and extension interfaces..
  • <GL/glcorearb.h> - OpenGL core profile and ARB extension interfaces, as described in appendix G.2 of the OpenGL 4.3 Specification. Does not include interfaces found only in the compatibility profile.
  • <GL/glxext.h> - GLX 1.3 and above API and GLX extension interfaces.
  • <GL/wglext.h> - WGL extension interfaces.

Linux

On Linux you need to link against libGL.so, which is usually a symlink to libGL.so.1, which is yet a symlink to the actual library/driver which is a part of your graphics driver. For example, on my system the actual driver library is named libGL.so.256.53, which is the version number of the nvidia driver I use. You also need to include the gl.h header, which is usually a part of a Mesa or Xorg package. Again, you might need glext.h and glxext.h from http://www.opengl.org/registry . glxext.h holds GLX extensions, the equivalent to wglext.h on Windows.

If you want to use OpenGL 3.x or OpenGL 4.x functionality without the functionality which were moved into the GL_ARB_compatibility extension, use the new gl3.h header from the registry webpage. It replaces gl.h and also glext.h (as long as you only need core functionality).

Last but not the least, glaux.h is not a header associated with OpenGL. I assume you've read the awful NEHE tutorials and just went along with it. Glaux is a horribly outdated Win32 library (1996) for loading uncompressed bitmaps. Use something better, like libPNG, which also supports alpha channels.


If you're on Windows, they are installed with the platform SDK (or Visual Studio). However the header files are only compatible with OpenGL 1.1. You need to create function pointers for new functionality it later versions. Can you please clarify what version of OpenGL you're trying to use.


Some of the answers above, in regards to linux, are either incomplete, or flat out wrong.

For example, /usr/include/GL/gl.h is not part of mesa-common-dev or has not been for many years.

At any rate, for a more current answer, these two packages are important:

https://mesa.freedesktop.org/archive/mesa-20.1.2.tar.xz

ftp://ftp.freedesktop.org/pub/mesa/glu/glu-9.0.1.tar.xz

The glu.h is part of glu itself:

GL/glu.h
GL/glu_mangle.h

Mesa is evidently significantly larger. Its headers are a bit variable, I suppose, depending on the flags given to meson, but should include these typically:

KHR/khrplatform.h                                                                                                         
EGL/eglplatform.h                                                                                                         
EGL/eglext.h                                                                                                              
EGL/eglextchromium.h                                                                                                      
EGL/eglmesaext.h                                                                                                          
EGL/egl.h                                                                                                                 
vulkan/vulkan_intel.h
gbm.h
GLES3/gl31.h
GLES3/gl3ext.h
GLES3/gl3.h
GLES3/gl32.h
GLES3/gl3platform.h
xa_composite.h
xa_tracker.h
xa_context.h
GLES2/gl2.h
GLES2/gl2platform.h
GLES2/gl2ext.h
GLES/gl.h
GLES/glplatform.h
GLES/glext.h
GLES/egl.h
GL/gl.h
GL/glx.h
GL/osmesa.h
GL/internal
GL/internal/dri_interface.h
GL/glcorearb.h
GL/glxext.h
GL/glext.h

Hope that helps anyone finding an answer this question in the future; compiling dosbox needs this, for instance, due to SDL opengl.


In Visual Studio :

//OpenGL
#pragma comment(lib, "opengl32")
#pragma comment(lib, "glu32")
#include <gl/gl.h>
#include <gl/glu.h>

Headers are in the SDK : C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl


What operating system?

Here on Ubuntu, I have

$ dpkg -S /usr/include/GL/gl.h 
mesa-common-dev: /usr/include/GL/gl.h
$ 

but not the difference in a) capitalization and b) forward/backward slashes. Your example is likely to be wrong in its use of backslashes.


Debian Linux (e.g. Ubuntu)

sudo apt-get update
OpenGL: sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev

Windows

Locate your Visual Studio folder for where it puts libraries and also header files, download and copy lib files to lib folder and header files to header. Then copy dll files to system32. Then your code will 100% run.

Also Windows: For all of those includes you just need to download glut32.lib, glut.h, glut32.dll.