Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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 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?

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!)

like image 343
ExOttoyuhr Avatar asked Jul 30 '13 21:07

ExOttoyuhr


People also ask

How do I install OpenGL on Windows 10?

On the official site, navigate to the graphics driver and choose your operating system. Download the latest drivers for your graphics card and install it to your computer. This will also update the OpenGL on your computer. Otherwise, it makes sense to get the OpenGL driver from the graphics driver within Windows 10.

Can you download OpenGL?

Kepler GPU ArchitectureThe OpenGL 4.6 specifications can be downloaded from http://www.opengl.org/registry/.


1 Answers

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.

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.

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.

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:

  • 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

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. 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.

like image 61
datenwolf Avatar answered Oct 03 '22 20:10

datenwolf