Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the latest OpenGL?

Tags:

c++

opengl

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.
like image 944
Blub Avatar asked Jul 22 '10 13:07

Blub


2 Answers

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.

like image 99
Tomaka17 Avatar answered Sep 22 '22 17:09

Tomaka17


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?

like image 21
Greg S Avatar answered Sep 20 '22 17:09

Greg S