如何为 Windows C++ 安装当前版本的 OpenGL? [英] How do I install a current version of OpenGL for Windows C++?

查看:34
本文介绍了如何为 Windows C++ 安装当前版本的 OpenGL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Visual Studio 2010 运行 Windows 7.包含的 OpenGL 版本 (#include) 是 1.1 版,我希望使用合理的当前版本 - 某种版本 3 或 4.

I'm running Windows 7 with Visual Studio 2010. The version of OpenGL included (#include ) is version 1.1, and I'd like to be working with a reasonably current version -- some sort of version 3 or 4.

我需要做什么才能达到那个状态?http://www.opengl.org/sdk/ 的 OpenGL SDK 页面似乎说您不允许下载 SDK,http://www.opengl.org/wiki/Getting_Started 上的 OpenGL wiki 说你'预计已经拥有它,如果没有,它会将您指向可以下载图形卡制造商的 DLL 的站点.但我肯定不需要为我将要使用的每张显卡构建我正在开发的游戏的不同版本.

What do I need to do in order to get to that state? The OpenGL SDK page at http://www.opengl.org/sdk/ seems to say that you're not allowed to download the SDK, and the OpenGL wiki at http://www.opengl.org/wiki/Getting_Started says that you're expected to already have it, and if you don't have it, it points you to sites where you can download graphics-card manufacturers' DLLs. But surely I don't need to build a different version of the game I'm working on for each graphics card I'm going to be working with.

StackOverflow 似乎也没有任何内容,至少没有以我可以遵循的方式表达.我只想要一个我可以运行的安装程序的下载链接,这会给我一个合理的最新 OpenGL API ......我去哪里获取它?

StackOverflow also doesn't seem to have anything, at least not phrased in a way that I can follow. I just want a download link to an installer that I can run, which will leave me with a reasonably up-to-date OpenGL API... Where do I go to get it?

更新: OpenGL 似乎具有某种不涉及拥有 SDK 的异质习语——即 .DLL、.lib 和标头的包.我正在使用 DirectX,它确实如此.(事实上​​,DirectX SDK 甚至包括文档!)

Update: OpenGL appears to have an ideosyncratic idiom of some sort which doesn't involve having an SDK -- i.e., a package of .DLL, .lib, and headers. I'm using DirectX, which does. (In fact, the DirectX SDK even includes documentation!)

推荐答案

首先,OpenGL 不是一些集中管理的库和实现(与 DirectX 相对),这就是为什么你不能下载SDK,因为这不是 OpenGL 的工作方式.OpenGL 本身只是一堆描述驱动程序提供和程序可以使用的 API 的文档.但是,API 的实际实现存在于操作系统的上下文中.如果您希望 API 独立于操作系统,这会让事情变得有点困难.DirectX 很简单,因为它只为一种特定的操作系统而设计.该操作系统是 Windows,这意味着 DirectX 可以针对底层操作系统的一部分编写.这使得 SDK 的开发变得易于管理.

First of all OpenGL is not some centrally managed library and implementation (opposed to DirectX), that's why you can't download the SDK, because that's not how OpenGL works. OpenGL itself is just a bunch of documents that describe an API that drivers provide and programs can use. However, the actual implementation of the API lives in the context of an operating system. And that makes things a little bit difficult if you want your API to be independent of an OS. DirectX has it easy, because it's designed for only one particular OS. That OS is Windows and that means DirectX can be written against parts of the underlying OS. Which makes development of an SDK manageable.

那么 OpenGL 会做什么呢?好吧,它要求操作系统的某些部分如此慷慨并使其可供程序使用.在最简单的形式中(事后看来,这将是更好的选择,因为它可以省去很多像您一样的问题)这个接口将提供一个函数:GetProcAddress.对于 OpenGL 规范中的每个函数,您都可以通过该函数获得指向 OpenGL 驱动程序中实际内容的指针.但是,像大多数程序员一样懒惰,他们采取了简单的方式说:哦,好吧,OpenGL 的当前规范是 1.1 版,我们如何在接口库的表面上公开所有 OpenGL-1.1.以及所有在我们通过 GetProcAddress 加载的扩展公开之后;毕竟,会有多少新功能......".事实证明:很多.

So what does OpenGL do then? Well, it requires that some part of the OS will be so generous and make it available to the program. In the most simple form (and in hindsight this would have been the better option, because it would save so many questions like yours) this interface would have provided exactly one function: GetProcAddress. For each and every function found in the OpenGL spec you could have got a pointer to the actual thing in your OpenGL driver by that function. But, lazy as most programmers are they went the easy way and said: "Oh well, the current spec of OpenGL it at version 1.1, how about we expose all of OpenGL-1.1 on the interfacing library's surface. And everything that comes after we expose through extensions that are to be loaded by GetProcAddress; after all, how much new functionality will there be…". Turns out: A lot.

无论如何,每个为操作系统提供支持的编译器都应该为操作系统附带的每个 API 提供接口库.对于 Windows,它是 OpenGL-1.1.如果您想要 OpenGL 接口库上的实际版本提升,那将意味着操作系统更新.但这与 DirectX 并没有太大不同,DirectX 的新 DirectX 版本随操作系统更新一起提供.只是微软没有看到支持 OpenGL 的理由.所以 OpenGL-1.1 是表面可见的,我们必须处理它.而且由于它包含在编译器附带的内容中,因此没有理由提供实际的 SDK 以供下载,因为所需的一切都已在您的编译器安装中.

Anyway, every compiler offering support for an OS is supposed to provide interface libraries for every API the OS ships with. Which for Windows is OpenGL-1.1. If you want an actual version bump on the OpenGL interface library, that would mean an OS update. But that's not so different from DirectX, where new DirectX versions are shipping with OS updates. It's just that Microsoft doesn't see a reason to support OpenGL. So OpenGL-1.1 is what's visible on the surface and we have to deal with it. And since it's included in what compilers ship there's no reason for providing an actual SDK to download, because everything necessary is already right there on your compiler installation.

好的,那么如何从更高版本 OpenGL 中获取这些函数呢?那么:GetProcAddress.这是官方的做法.并且因为实际细节取决于所讨论的操作系统,但 OpenGL 是独立于操作系统的,所以根本不可能有确定性 OpenGL SDK.所以正式你必须做的是:

Okay, so how to get those functions from later versions of OpenGL then? Well: GetProcAddress. That's the official way to do it. And because the actual details depend on the OS in question, but OpenGL is OS independent there simply can not be a definitive OpenGL SDK. So officially what you have to do is:

  • http://opengl.org/registry
  • 下载更高版本的 OpenGL 标头
  • 为每个要使用的函数定义一个函数指针变量来保存它
  • 使用GetProcAddress
  • 加载函数指针
  • Download the OpenGL headers for later versions from http://opengl.org/registry
  • For each function you want to use define a function pointer variable to hold it
  • Load the function pointer using GetProcAddress

当然,如果您只想使用现代 OpenGL,这会相当乏味.所以有些人开发了 3rd 方工具来为你做事.对于您作为程序员所关心的一切,这些工具的行为非常类似于 SDK.迄今为止最受欢迎的选择(但不幸的是,它并非完全没有问题,就 OpenGL 的前沿而言)是 GLEW.使用 GLEW 非常简单.我建议使用静态链接:

Of course if you just want to use modern OpenGL this is rather tedious. So some people developed 3rd party tools that do the deed for you. And for everything that concerns you as programmer, these tools behave very much like an SDK. The most popular choice so far (but unfortunately it's not completely trouble free, with regard of the bleeding edge of OpenGL) is GLEW. Using GLEW is quite easy. I recommend using it statically linked:

  1. http://glew.sourceforge.net
  2. 下载 GLEW
  3. 将glew.c 和glew.h 与您的项目源文件放在一起.
  4. 将glew.c 添加到编译源列表中;确保将 GLEW_STATIC 预处理器宏定义配置到您的项目全局编译器标志中.
  5. 使用 #include "glew.h" 而不是 #include
  6. 在您在程序中创建 OpenGL 窗口之后立即调用 glewInit()
  1. Download GLEW from http://glew.sourceforge.net
  2. Place glew.c and glew.h alongside your projects source files.
  3. Add glew.c to the list of compiled sources; make sure to have the GLEW_STATIC preprocessor macro definition be configured into your projects global compiler flags.
  4. Use #include "glew.h" instead of #include <GL/gl.h>
  5. Right after you created an OpenGL window in your program call glewInit()

现在有一些建议:您应该真正学会阅读文档(而不仅仅是略读).我刚刚写的所有内容都在您链接的参考资料中说明.

Now some advice: You should really learn to read documentation (not just skim it). All of what I've just written is stated on the very references you linked.

这篇关于如何为 Windows C++ 安装当前版本的 OpenGL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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