Q:

How do game engines manage to 'detect' the opengl supported in a computer

I am learning OpenGL 3.3 and OpenGL 2.1. I want to make a game engine with both. So far I can do advanced stuff with both of them. I noticed that graphics engines like Irrlicht support OpenGL 1.x to 4.x. When i run an Irrlicht program in my computer that supports OpenGL 3.3, it runs perfectly. And when i run it in a computer with OpenGL 2.1, it still runs perfectly.
How does it know that my computer supports OpenGL 3.3, and adapt itself to it. Is it through trial and error? or how are they able to do this. That is a feature i want to incorporate in my game engine.

A:

What works for me is simple:
// create OpenGL context first, gl** functions dont work without it

fOpenGL_Vendor   := String(glGetString(GL_VENDOR));
fOpenGL_Renderer := String(glGetString(GL_RENDERER));
fOpenGL_Version  := String(glGetString(GL_VERSION)); // <-- this 

Last line returns OpenGL version reported by GPU driver, in a x.x.x format. You can trim last .x from it to get common 2-digit version format.

For example this is breakdown from my game:
Count   Version
2175    4.5
684     3.3
435     4.0
331     4.4
262     4.3
248     3.1
216     4.2
97      3.0
75      4.1
73      2.1

