Search code examples
c++linuxopengldriversvideo-card

(linux) How can I know inside a c++ program if Opengl 4 is supported?


I would like to detect inside my C++ program if opengl 4 is supported on the running computer.

I don't know if I search on google and stackoverflow with wrong/bad terms (my english skill...), but surprisingly I didn't found any example... I would not be suprise if you tell me this question is a duplicate...

It would eventually useful for me to know how to get more usefull datas from the video card and the drivers used by it on the running computer. I didn't take time to look around to know how to do that, but if you have some usefull link, feel free to share it with me.


Solution

    • Step 1: Create an OpenGL Context; first try by the "attrib" method requesting the minium OpenGL version you want to have. If that succeeds you're done.

    • Step 2: If that didn't work and you can gracefully downgrade create a no-frills context and call glGetString(GL_VERSION) to get the actual context version supported. Note that on MacOS X this limits you to 2.1 and earlier.

    • Step 3: If you want some context, portable and reliably between 2.1 and your optimimal version, try with the attribs method in a loop, decrementing your needs until it succeeds.

    Note that there is no way to determine in advance which version is supported in OpenGL. The main reason for this is, that operating systems and the graphics layer may decide on demand which locally available OpenGL version to use, depending on the request and the resources available at the moment (graphics cards in theory can be hotplugged).