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

问题描述

我正在Windows 7和Visual Studio 2010上运行.所包含的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相对),这就是为什么您无法下载 the 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,这将非常乏味.因此,有些人开发了第三方工具来为您做事.对于您作为程序员所关心的所有事情,这些工具的行为都非常类似于SDK.到目前为止,最流行的选择是GLEW(但不幸的是,就OpenGL的尖端而言,它并不是完全没有问题).使用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 <GL/gl.h>
  6. 在程序调用glewInit()
  7. 中创建OpenGL窗口之后
  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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 10:25