OpenGL 文件 glew.h 和 gl.h/glu.h 之间的区别 [英] Difference between OpenGL files glew.h and gl.h/glu.h

查看:51
本文介绍了OpenGL 文件 glew.h 和 gl.h/glu.h 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 Windows 7 专业版中默认包含的 glu 和 gl 头文件构建了一个 OpenGL 程序.现在,我买了一本描述 OpenGL 游戏开发的书.这本书的作者说,我必须在我的项目中包含glew头文件.完成此操作后,我遇到了一些未解决的外部符号错误.

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.

所以,现在我真的很困惑.我之前在我的程序中使用过 glBegin 和 glEnd 语句.现在我必须使用 glBindBuffers 和 glGenBuffer 等,但我得到了未解决的外部符号错误,如下所示:

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

推荐答案

你在这里混淆了 3 种不同的东西:

You're mixing up 3 different things here:

  1. OpenGL
  2. 不属于 OpenGL 的 GL 实用程序 (GLU)
  3. 和 GL Extension Wrangler (GLEW)

GLEW 和 GLU 是完全不同的东西,你不能用另一个来代替.

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

GL/gl.h 是基本的 OpenGL 头文件,它为您提供 OpenGL-1.1 函数和令牌声明,也许更多.对于 1.1 版以外的任何内容,您必须使用 OpenGL 扩展机制.由于这是一项枯燥乏味的任务,因此 GLEW 项目已将其自动化,该项目将所有脏细节都打包在一个易于使用的库中.这个库的声明可以在头文件 GL/glew.h 中找到.由于没有基本的 OpenGL,Op​​enGL 扩展就没有意义,GLEW 标头隐含地包含常规 OpenGL 标头,因此在包含 GL/glew.h 后,您不再需要包含 GL/gl.h.

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.

然后是 GLU,一组方便的方法,顺便说一句,这些方法已经严重过时,不应在任何现代 OpenGL 程序中使用.没有现代 GLU,所以忘掉它吧.无论如何,它的声明由标头 GL/glu.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).

你得到的错误与包含文件无关.这些是链接器错误.仅包括声明只是工作的一半.另一半是链接实际的定义,而那些不在库文件头中的;libglew.solibglew.a 在 *nix 操作系统上,glew.libglew32.libglews.lib 或 glew32s.lib.如果不使用静态版本(没有 's' 的版本),您还必须安装正确的 DLL.

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.

因此要使用 GLEW,您需要包含标题将其添加到链接器选项中的库列表中.此外,您必须在程序中获得 OpenGL 上下文后调用 glewInit();.

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.

这篇关于OpenGL 文件 glew.h 和 gl.h/glu.h 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆