简体   繁体   English

如何为Windows C ++安装当前版本的OpenGL?

[英]How do I install a current version of OpenGL for Windows C++?

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. 我正在使用Visual Studio 2010运行Windows 7.包含OpenGL的版本(#include)是版本1.1,我想使用合理的当前版本 - 某种版本3或4。

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. http://www.opengl.org/sdk/上的OpenGL SDK页面似乎表示您不允许下载SDK,并且http://www.opengl.org/wiki/Getting_Started上的OpenGL wiki说您应该已经拥有它,如果您没有它,它会指向您可以下载图形卡制造商的DLL的网站。 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 also doesn't seem to have anything, at least not phrased in a way that I can follow. StackOverflow似乎也没有任何东西,至少没有以我能遵循的方式表达。 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 API ...我该去哪里获取它?

Update: OpenGL appears to have an ideosyncratic idiom of some sort which doesn't involve having an SDK -- ie, a package of .DLL, .lib, and headers. 更新: OpenGL似乎具有某种类型的同义词习惯用法,它不涉及拥有SDK - 即包含.DLL,.lib和头文件。 I'm using DirectX, which does. 我正在使用DirectX。 (In fact, the DirectX SDK even includes documentation!) (事实上​​,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的是不是有些集中管理库和实现(反对的DirectX),这就是为什么你不能下载 SDK,因为这是OpenGL的不是如何工作的。 OpenGL itself is just a bunch of documents that describe an API that drivers provide and programs can use. OpenGL本身只是一堆描述驱动程序提供的API和程序可以使用的文档。 However, the actual implementation of the API lives in the context of an operating system. 但是,API的实际实现存在于操作系统的上下文中。 And that makes things a little bit difficult if you want your API to be independent of an OS. 如果您希望您的API独立于操作系统,这会让事情变得有点困难。 DirectX has it easy, because it's designed for only one particular OS. DirectX很容易,因为它只适用于一个特定的操作系统。 That OS is Windows and that means DirectX can be written against parts of the underlying OS. 该操作系统是Windows,这意味着可以针对底层操作系统的某些部分编写DirectX。 Which makes development of an SDK manageable. 这使得SDK的开发可管理。

So what does OpenGL do then? 那么OpenGL会做什么呢? 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 . 以最简单的形式(事后看来,这将是更好的选择,因为它可以保存像你这样的许多问题)这个接口只能提供一个函数: 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. 对于OpenGL规范中的每个函数,您可以通过该函数获得指向OpenGL驱动程序中实际内容的指针。 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…" . 但是,懒得像大多数程序员一样,他们走得很简单并且说: “哦,好吧,OpenGL的当前版本在版本1.1,我们如何在接口库的表面上公开所有的OpenGL-1.1。以及我们之后发生的一切通过GetProcAddress加载的扩展来公开;毕竟,有多少新功能......“ Turns out: A lot. 事实证明:很多。

Anyway, every compiler offering support for an OS is supposed to provide interface libraries for every API the OS ships with. 无论如何,每个提供OS支持的编译器都应该为OS附带的每个API提供接口库。 Which for Windows is OpenGL-1.1. 适用于Windows的是OpenGL-1.1。 If you want an actual version bump on the OpenGL interface library, that would mean an OS update. 如果您想在OpenGL接口库上实际版本颠簸,那将意味着操作系统更新。 But that's not so different from DirectX, where new DirectX versions are shipping with OS updates. 但这与DirectX没有什么不同,DirectX是新的DirectX版本随OS更新发布的。 It's just that Microsoft doesn't see a reason to support OpenGL. 只是微软没有理由支持OpenGL。 So OpenGL-1.1 is what's visible on the surface and we have to deal with it. 所以OpenGL-1.1是表面上可见的,我们必须处理它。 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. 而且由于它包含在编译器发布的内容中,因此没有理由提供实际的SDK来下载,因为在编译器安装中已经有了必要的一切。

Okay, so how to get those functions from later versions of OpenGL then? 好的,那么如何从更高版本的OpenGL中获取这些功能呢? Well: GetProcAddress . 好吧: 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. 并且因为实际的细节取决于所讨论的操作系统,但OpenGL与操作系统无关,因此根本不可能是一个明确的 OpenGL SDK。 So officially what you have to do is: 所以你要正式做的是:

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

Of course if you just want to use modern OpenGL this is rather tedious. 当然,如果你只是想使用现代的OpenGL,这是相当繁琐的。 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. 对于那些与程序员有关的事情,这些工具的行为非常类似于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. 到目前为止最受欢迎的选择(但不幸的是,关于OpenGL的前沿,它并非完全无故障)是GLEW。 Using GLEW is quite easy. 使用GLEW非常简单。 I recommend using it statically linked: 我建议使用它静态链接:

  1. Download GLEW from http://glew.sourceforge.net http://glew.sourceforge.net下载GLEW
  2. Place glew.c and glew.h alongside your projects source files. 将glew.c和glew.h放在项目源文件旁边。
  3. Add glew.c to the list of compiled sources; 将glew.c添加到已编译源列表中; make sure to have the GLEW_STATIC preprocessor macro definition be configured into your projects global compiler flags. 确保将GLEW_STATIC预处理器宏定义配置到项目全局编译器标志中。
  4. Use #include "glew.h" instead of #include <GL/gl.h> 使用#include "glew.h"代替#include <GL/gl.h>
  5. Right after you created an OpenGL window in your program call glewInit() 在程序中创建OpenGL窗口后立即调用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. 我刚刚写的所有内容都在你链接的参考文献中说明。

Let me answer by quoting the link you provided 让我通过引用您提供的链接来回答

For most libraries you are familiar with, you simply #include a header file, make sure a library is linked into your project or makefile, and it all works. 对于您熟悉的大多数库,您只需#include一个头文件,确保库链接到您的项目或makefile,这一切都有效。 OpenGL doesn't work that way. OpenGL不能那样工作。 For reasons that are ultimately irrelevant to this discussion, you must manually load functions via a platform-specific API call. 由于最终与此讨论无关的原因,您必须通过特定于平台的API调用手动加载函数。 This boilerplate work is done with various OpenGL loading libraries; 这个样板工作是通过各种OpenGL加载库完成的; these make this process smooth. 这些使这个过程顺利进行。 You are strongly advised to use one . 强烈建议您使用一个

this passage contains a handy link to a wiki page entitled OpenGL Loading Library 这段文章包含一个方便的链接到一个名为OpenGL Loading Library的wiki页面

As so far as I can tell with working in the OpenTK framework(C#) and the JOGL framework(Java), your OpenGL version is determined by your graphics card. 据我所知,在OpenTK框架(C#)和JOGL框架(Java)中工作,您的OpenGL版本由您的图形卡决定。 I know my laptop only supports OpenGL 1.1 on my desktop it supports the most recent version. 我知道我的笔记本电脑仅在我的桌面上支持OpenGL 1.1,它支持最新版本。

Laptop has an Intel IGP with an I5 proc. 笔记本电脑有英特尔IGP和I5触发器。

Desktop has a Radeon 6950HD. 桌面有一个Radeon 6950HD。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM