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

删除回忆录丶 提交于 2019-11-28 16:54:32

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.

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!