Difference between OpenGL files glew.h and gl.h/glu.h

24,042

Solution 1

You're mixing up 3 different things here:

  1. OpenGL
  2. the GL Utilities (GLU) which are not part of OpenGL
  3. and the GL Extension Wrangler (GLEW)

GLEW and GLU are completely different things and you can not replace one with another.

GL/gl.h are the base OpenGL headers, which give you OpenGL-1.1 function and token declarations, any maybe more. For anything going beyond version 1.1 you must use the OpenGL extension mechanism. Since this is a boring and tedious task, that has been automatized by the GLEW project, which offer all the dirty details packed up in a easy to use library. The declarations of this library are found in the header file GL/glew.h. Since OpenGL extensions don't make sense without basic OpenGL, the GLEW header implicitly includes the regular OpenGL header, so as of including GL/glew.h you no longer need to include GL/gl.h.

Then there's GLU, a set of convenience methods, which BTW are seriously outdated and should not be used in any modern OpenGL program. There's no modern GLU, so just forget about it. Anyway, it's declarations are made available by the header GL/glu.h (the one you were asking about).

The errors you get have nothing to do with include files though. Those are linker errors. Just including the declarations is only half of the job. The other half is linking the actual definitions and those are not in the header by the library file; libglew.so or libglew.a on a *nix OS, glew.lib or glew32.lib or glews.lib or glew32s.lib on Windows. If not using the static versions (those without the 's') you also must have installed the right DLL.

So to use GLEW you need to include the header and add it to the list of libraries in the linker options. Also you must call glewInit(); once you've obtained a OpenGL context in your program.

Solution 2

  • gl: This is the base header file for OpenGL version 1.1. That means if you want to use any functionality beyond version 1.1, you have to add any extension library on this.
  • glew: OpenGL Extension Wrangler Library. This is a cross-platform library for loading OpenGL extended functionality. When you initialize this library, it will check your platform and graphic card at run-time to know what functionality can be used in your program.
  • glu: This is OpenGL utilities library, which has been not updated for long time. Don't need to use this header file.
  • glut: OpenGL Utility Toolkit for Windowing API. This is good for small to medium size OpenGL program. If you need more sophisticated windowing libraries, use native window system toolkits like GTK or Qt for linux machines.
  • glfw: OpenGL Frame Work. Another multi-platform library for creating windows and handling events. FreeGlut can be used as an alternative. glfw is designed for game development.
  • glm: OpenGL Mathematics. It helps implementing vectors and matrices operations.

I am very new to OpenGL stuff, so please correct me if I'm wrong.

Share:
24,042
SKiD
Author by

SKiD

Updated on July 09, 2022

Comments

  • SKiD
    SKiD almost 2 years

    I've built an OpenGL program with my glu and gl header files default included in windows 7 professional edition. Now, I've bought a book that describes OpenGL game development. The author of this book said, I have to include the glew header into my project. After I've done this I got some unresolved external symbol errors.

    So, now I'm really confused. I've worked earlier with glBegin and glEnd statements in my program. Now I've to work with glBindBuffers and glGenBuffer etcetera, but I get the unresolved external symbol errors, like that:

    1>cWindows.obj : error LNK2001: unresolved external symbol __imp___glewBindBuffer
    1>cMdlLoader.obj : error LNK2001: unresolved external symbol __imp___glewBindBuffer
    1>cMdlLoader.obj : error LNK2001: unresolved external symbol __imp___glewBufferData
    1>cMdlLoader.obj : error LNK2001: unresolved external symbol __imp___glewGenBuffers
    

    Is there anyone here who can explain the difference between these header files and what I have to do with them?

    I goggled many times, but on different sites there are much more confusing words like "glee" or "glut".

  • BiMo
    BiMo almost 2 years
    If I am not wrong, you might miss two more libraries (1) FreeGLUT which at the same time include the OpenGL extensions like glew/glad and windowing like glfw. FreeGLUT often recommended. (2) The second library is glad, what works similarly to glew
  • BiMo
    BiMo almost 2 years
    Is there any difference between GL/gl.h, and GL/GL.h? If I remember correctly, in some boiler plate codes I have also seen header like GL/GL.h.
  • datenwolf
    datenwolf almost 2 years
    @BiMo: GL/GL.h is malformed and only works when compiling on Windows, since there file names are not case sensitive. If you'd try to compile project using that on an operating system that does compare filenames in a case sensitive manner (which all operating systems with support for OpenGL is everything but Windows), it would fail.
  • BiMo
    BiMo almost 2 years
    Aha! So, although OpenGL is cross platform same GL/GL.h will be an error in Linux. Thanks for the clarification.
  • datenwolf
    datenwolf almost 2 years
    @BiMo: Well, that's not really an OpenGL problem, but a lapse of the programmer. If you look at the headers shipping with compilers targeting Windows (remember, OpenGL-1.1 is part of the set of base Win32 APIs), you'll find that the OpenGL header is named GL/gl.h in those. If a programmer writes GL/GL.h then they were just care or clueless.