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.