c++ - 在 C++、Windows 7 中包含 OpenGL 库

标签 c++ windows opengl compilation c-preprocessor

我正在阅读“OpenGL 入门”教程,我看到了这段文字:

"If you are using C/C++, then you must first set up a build environment (Visual Studio project, GNU makefile, CMake file, etc) that can link to OpenGL. Under Windows, you need to statically link to a library called OpenGL32.lib (note that you still link to OpenGL32.lib if you're building a 64-bit executable. The "32" part is meaningless). Visual Studio, and most Windows compilers, come with this library."

我只是尝试使用 vim 编写我的源文件,我不想使用像 VS 这样的 IDE,并且根据我的理解,OpenGL 库随 Windows 7 一起提供(如果我错了请纠正我)。在这一点之后,本文并没有真正详细介绍如何包含 OpenGL 库,我真正的问题是,如何在我的源文件中包含和使用 OpenGL 库?

是不是写#include <name of lib>这么简单或者我是否需要对我的编程环境做一些其他事情,比如编辑我的路径变量?

编辑:我正在使用 MinGW g++/gcc 编译器

最佳答案

要访问包含文件,您需要一个特殊的支持库。其中不止一种,但我会推荐 GLEW。您可以在 http://glew.sourceforge.net/ 找到 GLEW 界面.

这是因为在 Windows 上默认只有非常旧版本的 OpenGL header 可用。较新的界面是间接可用的;您必须询问功能地址。然而,这是由 GLEW 为您完成的。

所以你只需要包含 ,并用 glewInit() 做一些初始化;

这与 Linux 和 Windows 兼容,尤其是当您使用 MinGW 时。链接时,我使用以下内容:

我的库 = -lglew32 -lopengl32 -lWs2_32 -lole32 -lcomctl32 -lgdi32 -lcomdlg32 -luuid

我可以推荐使用通用的 makefile,参见 http://sourceforge.net/projects/gcmakefile/

请注意,您还必须设置一个 context对于 OpenGL,在初始化 GLEW 之前。这取决于环境的不同。当你打开一个窗口时,它就完成了。对于可移植库,我可以推荐 glfw图书馆或 freeglut .

关于c++ - 在 C++、Windows 7 中包含 OpenGL 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12376225/

相关文章:

c++ - 识别 LLVM 中 block 的封闭循环

c - LIne 不使用 glFrustum() 显示?

windows - Windows 上 Redis 的日志文件

c++ - glUseProgram() 和速度之后 uniform 的行为

c++ - 在 MacOSX 上编译 OpenGL 程序时出错 ('ld: library not found for -lopengl32' )

c++ - 参数化对象的 vector

C++ 解释将 uint64 转换为 uint32

c++ - 需要从格式化字符串移动到二进制缓冲区

windows - 设置与Windows SFTP服务器的WSO2 Enterprise Integrator VFS连接

c++ - 在 C++ 中返回运行时可用虚拟内存的大小