11

quite new to the subject, and in college we were provided with the .dlls each time we needed them. But I never had any idea what actual version I was using, what extensions I was using...This is very confusing to be honest. I couldn't find any download link on the official khronos site. Clicking on the OpenGL SDK link, just presents me with more documentation. I'm used to DirectX, which makes it pretty clear what version you are using. (by the device you create).

  1. How would I start using OpenGL 4.0 today?
  2. How would I enable an extension?
  3. How do I know what version of OpenGL my machine is capable of?
  4. Did anything big change in 4.0? I don't think I need to care about old versions because I code OpenGL purely for educational purposes for at least another 2 years.
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Blub
  • 13,014
  • 18
  • 75
  • 102

3 Answers3

11

OpenGL is not a library with different version numbers, and such. Instead it is one big standard which graphics drivers must support by themselves. Consequently, some graphics cards may not support latest OpenGL versions, while in the future some cards may not support older versions.

You don't need to include a different header or link to a different library if you use OpenGL 1.0 or if you use OpenGL 4.0. However to use OpenGL 4.0 you have to detect if it is supported by the machine your program is running on. For the moment, only very recent GPUs support OpenGL 4.0. You may have better chances with OpenGL 3.0

If you are on Windows, include "gl/gl.h" and link your program with "OpenGL32.lib"

Once your program is started, you can detect the version of OpenGL supported by the GPU or enable an extension using glString and wglGetProcAddress. However I strongly advise you to use a third-party library (GLee being my favorite).

Programming with OpenGL is quite different than programming with DirectX. DirectX is guaranteed to support all the functionnalities of the version you're using. When you code something with OpenGL, you should rather detect each functionnality individually.

For example, say you want to use a vertex buffer. Your code should be like this:

  • if OpenGL version >= 2, then use glGenBuffers, glBindBuffer, etc.
  • else, allocate and fill data in RAM

You can see some examples in the GLee page I linked above

Of course you can't do this for everything. Shaders, for example, can't be done without a certain extension and you should simply display an error message if they are not available.

More complicated: starting from OpenGL 3, some functions have been deprecated. You now have two ways to initialisate OpenGL:

  • the new way (wglCreateContextAttribsARB on Windows) where you precise the minimum OpenGL version you want
  • the old way (wglCreateContext) which requests a minimum of OpenGL 1.1 (recent versions being accessible, too)

If you request a version superior to OpenGL 3, the deprecated functions are theorically only accessible thanks to the extension ARB_compatibility which may be supported or not by the card. For the moment ARB_compatibility is supported by all existing GPUs but in the future it may no longer be so.

If you request a version inferior to OpenGL 3, these functions are not considered deprecated but the initialisation will fail if they are no longer supported by the card.

Tomaka17
  • 4,832
  • 5
  • 29
  • 38
  • GLUT is a portable library which allows you to create an OpenGL window and retrieve user input, while GLee allows you to easily use functions coming from extensions or more recent versions – Tomaka17 Jul 22 '10 at 14:34
  • 1
    Note that GLEW supports OpenGL 4.0, while GLee only supports OpenGL up to version 3.0. – Greg S Jul 22 '10 at 14:54
  • GLEW and GLee are almost the same, I personnally prefer GLee because it is lighter but the difference is not big – Tomaka17 Jul 22 '10 at 15:00
  • Alright, it looks like we used GLUT in all our programming samples in college. I'll use freeglut or something like that. I'll mark this as answer because it has much more info related to what I asked. – Blub Jul 22 '10 at 15:01
3

How would I start using OpenGL 4.0 today?

Simple answer: today, it's probably hard. There is almost no commodity hardware supporting OpenGL 4.0 available and the specification itself has only been released four months ago.

How would I enable an extension?

Use a solution like GLEW or GLee.

How do I know what version of OpenGL my machine is capable of?

See answer 2, both packages provide that info.

Did anything big change in 4.0? I don't think I need to care about old versions because I code OpenGL purely for educational purposes for at least another 2 years.

You definitely need to care about "old" versions, see answer 1, especially because not even OpenGL 3.x support is widely available today.

For some further information, you might want to take a look at this question: How many users could run software that uses OpenGL 3.x?

Community
  • 1
  • 1
Greg S
  • 12,333
  • 2
  • 41
  • 48
  • May I correct you on the fact that consumer hardware had had OpenGL 3.x for a couple of months now. Nvidia and ATI have done a nice job getting us support fast on the newer cards (which include everything back to 2 years (!)). Don't know about Intel, but if using fancy OpenGL is a concern, Intel wouldn't be an option, really. – rubenvb Jul 22 '10 at 14:26
  • So what do I need to download where to be able to use OpenGL? Whatever the latest supported version is? – Blub Jul 22 '10 at 14:30
  • 1
    NVIDIA supports OpenGL 4.0 in Windows driver 197.44 and Linux driver 195.36.07.04 and later on all of the 400-series "Fermi" chips. I believe ATi supports it on their 5000 series. OpenGL 3 support comes with every card since the GeForce 8-series and I think the Radeon 3000-series. – greyfade Jul 22 '10 at 14:39
  • @Blub: as pointed out by Tomaka17, OpenGL is not really a library but a standard. There is no OpenGL SDK you can download. Instead, use a library like SDL (http://www.libsdl.org/), which tremendously simplifies getting your first OpenGL window on the screen. – Greg S Jul 22 '10 at 14:41
  • What do you mean by "support comes with the card". Where do I find the .dll or lib which I need to include? I need to include some headers in my visual studio project, what I'm asking is, where to get those and everything else that is necessary for OpenGL development. I'm sure SDL also got it's libraries from somewhere right? – Blub Jul 22 '10 at 14:41
  • @Blub: a quick google search turned up this: http://thoughtsfrommylife.com/article-748-OpenGL_and_Visual_Studio_Express_2008 – Greg S Jul 22 '10 at 14:45
  • 1
    You have to include and link with OpenGL32.lib. In fact the OpenGL functions you call come directly from you video drivers but OpenGL32.lib acts as a bridge. – Tomaka17 Jul 22 '10 at 14:53
  • for everbody else: apparently the header and .lib already exist in a folder: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib – Blub Jul 23 '10 at 08:21
0

After OpenGL 1.2, all the extensions have to be loaded (if you are using windows) through the vendor-supplied interface for the graphics cards. In order for the cards to develop features that were still accessible to programmers, they use the OpenGL standard.

you'll need to include GL/gl.h which you should be able to find easily enough and u link to opengl32.a or whatever ur opengl library is. that gives you the very very basic functionality.

if you want to use most of the features, anything past 1.2, you'll need to either do some very specific very annoying extension loading calls for each function you want to use OR just grab glew or GLee. I've used both barely, not sure which i prefer. GLee is a bit lighter and I like it quite a bit but GLEW has got OpenGL 4 and they are both pretty dang solid so, probably glew for now imo i guess.

anyway this is a few months later and there are more and more cards with gl4 if you start developing in a opengl 3.1+ / 4 context now you'll be able to deploy it to most gaming or workstation computers after another year and a half for sure.