C++ 如何获取 GL 库/头文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3933027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:05:22  来源:igfitidea点击:

How to get the GL library/headers?

c++opengl

提问by cdxf

#include <gl\gl.h> 
#include <gl\glu.h> 
#include <gl\glaux.h>

This is an example, but where to get GL headers?

这是一个示例,但从哪里获取 GL 标头?

回答by

Windows

视窗

On Windows you need to include the gl.hheader for OpenGL 1.1 support and link against OpenGL32.lib. Both are a part of the Windows SDK. In addition, you might want the following headers which you can get from http://www.opengl.org/registry.

在 Windows 上,您需要包含gl.hOpenGL 1.1 支持的标头和针对 OpenGL32.lib 的链接。两者都是Windows SDK的一部分。此外,您可能需要以下标头,您可以从http://www.opengl.org/registry获得这些标头。

  • <GL/glext.h>- OpenGL 1.2 and above compatibility profile and extension interfaces..
  • <GL/glcorearb.h>- OpenGL core profile and ARB extension interfaces, as described in appendix G.2 of the OpenGL 4.3 Specification. Does not include interfaces found only in the compatibility profile.
  • <GL/glxext.h>- GLX 1.3 and above API and GLX extension interfaces.
  • <GL/wglext.h>- WGL extension interfaces.
  • <GL/glext.h>- OpenGL 1.2 及以上兼容性配置文件和扩展接口..
  • <GL/glcorearb.h>- OpenGL 核心配置文件和 ARB 扩展接口,如 OpenGL 4.3 规范的附录 G.2 中所述。不包括仅在兼容性配置文件中找到的接口。
  • <GL/glxext.h>- GLX 1.3 及以上 API 和 GLX 扩展接口。
  • <GL/wglext.h>- WGL 扩展接口。

Linux

Linux

On Linux you need to link against libGL.so, which is usually a symlink to libGL.so.1, which is yet a symlink to the actual library/driver which is a part of your graphics driver. For example, on my system the actual driver library is named libGL.so.256.53, which is the version number of the nvidia driver I use. You also need to include the gl.hheader, which is usually a part of a Mesa or Xorg package. Again, you might need glext.hand glxext.hfrom http://www.opengl.org/registry. glxext.hholds GLX extensions, the equivalent to wglext.hon Windows.

在 Linux 上,您需要链接 libGL.so,它通常是指向 libGL.so.1 的符号链接,它仍然是指向作为图形驱动程序一部分的实际库/驱动程序的符号链接。例如,在我的系统上,实际的驱动程序库名为 libGL.so.256.53,这是我使用的 nvidia 驱动程序的版本号。您还需要包含gl.h标头,它通常是 Mesa 或 Xorg 包的一部分。同样,你可能需要glext.hglxext.hhttp://www.opengl.org/registryglxext.h包含 GLX 扩展,相当于wglext.h在 Windows 上。

If you want to use OpenGL 3.x or OpenGL 4.x functionality without the functionality which were moved into the GL_ARB_compatibilityextension, use the new gl3.hheader from the registry webpage. It replaces gl.hand also glext.h(as long as you only need core functionality).

如果您想使用 OpenGL 3.x 或 OpenGL 4.x 功能而不使用已移至GL_ARB_compatibility扩展中的功能,请使用gl3.h注册表网页中的新标头。它取代了gl.hglext.h(只要您只需要核心功能)。

Last but not the least, glaux.his not a header associated with OpenGL. I assume you've read the awful NEHE tutorials and just went along with it. Glaux is a horribly outdated Win32 library (1996) for loading uncompressed bitmaps. Use something better, like libPNG, which also supports alpha channels.

最后但并非最不重要的glaux.h是,不是与 OpenGL 相关的头文件。我假设你已经阅读了糟糕的 NEHE 教程并且只是跟着它。Glaux 是一个非常过时的 Win32 库 (1996),用于加载未压缩的位图。使用更好的东西,比如 libPNG,它也支持 alpha 通道。

回答by Amir Zadeh

Debian Linux (e.g. Ubuntu)

Debian Linux(例如 Ubuntu)

sudo apt-get update
OpenGL: sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev

Windows

视窗

Locate your Visual Studio folder for where it puts libraries and also header files, download and copy lib files to lib folder and header files to header. Then copy dll files to system32. Then your code will 100% run.

找到您的 Visual Studio 文件夹,将其放置库和头文件的位置,将 lib 文件下载并复制到 lib 文件夹并将头文件复制到 header。然后将dll文件复制到system32。然后你的代码将 100% 运行。

Also Windows: For all of those includes you just need to download glut32.lib, glut.h, glut32.dll.

还有Windows:对于所有这些包括,您只需要下载glut32.libglut.hglut32.dll

回答by anno

In Visual Studio :

在 Visual Studio 中:

//OpenGL
#pragma comment(lib, "opengl32")
#pragma comment(lib, "glu32")
#include <gl/gl.h>
#include <gl/glu.h>

Headers are in the SDK : C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl

标头位于 SDK 中:C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl

回答by Dirk Eddelbuettel

What operating system?

什么操作系统?

Here on Ubuntu, I have

在 Ubuntu 上,我有

$ dpkg -S /usr/include/GL/gl.h 
mesa-common-dev: /usr/include/GL/gl.h
$ 

but not the difference in a) capitalization and b) forward/backward slashes. Your example is likely to be wrong in its use of backslashes.

但不是 a) 大写和 b) 向前/向后斜线的区别。您的示例在使用反斜杠时可能是错误的。

回答by Mark Ingram

If you're on Windows, they are installed with the platform SDK (or Visual Studio). However the header files are only compatible with OpenGL 1.1. You need to create function pointers for new functionality it later versions. Can you please clarify what version of OpenGL you're trying to use.

如果您使用的是 Windows,则它们与平台 SDK(或 Visual Studio)一起安装。然而,头文件只与 OpenGL 1.1 兼容。您需要为更高版本的新功能创建函数指针。您能否说明您尝试使用的 OpenGL 版本。