Difference between OpenGL files glew.h and gl.h/glu.h
Asked Answered
P

2

19

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".

Peshawar answered 25/8, 2012 at 14:0 Comment(0)
A
51

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.

Astrometry answered 25/8, 2012 at 14:15 Comment(4)
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.Hasin
@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.Astrometry
Aha! So, although OpenGL is cross platform same GL/GL.h will be an error in Linux. Thanks for the clarification.Hasin
@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.Astrometry
B
37
  • 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.

Berkshire answered 21/2, 2014 at 23:7 Comment(1)
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 glewHasin

© 2022 - 2024 — McMap. All rights reserved.