1

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.

The Unholy Metal Machine
  • 1,093
  • 2
  • 17
  • 36
  • @n.m.: That just tells you the GLX version available, which is completely unrelated to OpenGL. – datenwolf Sep 01 '14 at 17:50
  • Um, sorry, a slip of mind. http://www.opengl.org/wiki/Get_Context_Info – n. m. could be an AI Sep 01 '14 at 17:57
  • Opengl is considered as a third party library, it comes with .lib files and .dll files. All you need to do is to include these files on your compiler`s directory and set up your IDE environment to run it. The compiler will then rely on these .lib and .dll files to compile and execute Opengl programs. – Juniar Sep 01 '14 at 20:36
  • 1
    @Juniar ?? I guess wrong topic – The Unholy Metal Machine Sep 01 '14 at 20:43
  • I do not know if I understand your question. Are you setting up Opengl with C++? or you already have it set up? and is it linux OS platform? – Juniar Sep 01 '14 at 20:47
  • ok maybe it's not clear for you. Actually everything is set, compile and run. My question is/was to know how at the running time I can check if the video cards can use OpenGL 4.0 . Sorry if I wasn't clear – The Unholy Metal Machine Sep 01 '14 at 21:25
  • @Juniar: OpenGL **is not** a library. OpenGL is a system level API that gives access to functions offered by the graphics driver. The .lib is merely a thin API definition (and exists only for Windows compilers, on other systems there are not dedicated .lib files), the DLL is just a trampoline into the OpenGL implementation of the driver. However OP was **not** asking about Windows, but Linux, but it doesn't matter, because there as well, the libGL.so may be a trampoline wrapper as well. – datenwolf Sep 01 '14 at 23:38
  • @Juniar: Heck with GLX even on a headless system you may get GLX/OpenGL support if a remote connection from a GLX enabled X server is coming in. **Last but not least** The version of OpenGL supported is not determined by the available .lib (and DLL in the case of Windows). In fact the API exposed by the API definition library is stuck at OpenGL-1.x for either system. Anything that goes beyond OpenGL-1.2 must be loaded dynamically at runtime using {wgl,glX}GetProcAddress, **after** an OpenGL context has been created (in Windows the addresses actually depends on the OpenGL context active). – datenwolf Sep 01 '14 at 23:41

1 Answers1

1
  • 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).

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • All right then. "graphics cards in theory can be hotplugged" yeah... in practice... you cry... Thank you. – The Unholy Metal Machine Sep 01 '14 at 18:05
  • @bob-thetrashygravedigger: Oh, I can perfectly fine `ssh -YC` into the same computer from different X server machines and the local OpenGL client libraries don't change but the capabilities for the different display may vary a lot. Also in the future with the Wayland graphics model and indirecting display servers that may build on it, it may be dynamically decided if local or remote rendering is preferrable (for example for UIs rendering on the remote display server usually is preferrable, because the commands to render out UI elements take less bandwidth than transferring images). – datenwolf Sep 01 '14 at 18:09
  • ok for SSH I do that to on headless computer. but I'm not sure if a computer will accept to boot without a video card inside his chest... For wayland, I would be suprise if that will work without graphic card... but I don't know about it. I used virtualGL with a headless computer to make opengl working, but this needs a video cards, I guess it will be same with wayland. With virtualGL+VNC you can have a full remote X server ;) – The Unholy Metal Machine Sep 01 '14 at 18:55
  • @bob-thetrashygravedigger: Wayland is merely a framebuffer slinger **protocol** not an actual display server. You can use it to connect processes that somehow operate on the same framebuffers, like an application that draws to a framebuffer, that then gets composited by some kind of compositor. The actual implementation of drawing routines and policy is completely outside the scope of Wayland. OpenGL is outside the scope of Wayland. However the graphics model Wayland incubates makes things like GPU hotplugging much simpler. – datenwolf Sep 01 '14 at 19:17
  • @bob-thetrashygravedigger: Personally I don't like Wayland very much. IMHO it does too much in some areas and too little in others. Mostly I dislike that it has been designed on the assumption, that it will form the base for display servers frontsides. If you stripped away a few things (like the whole input event passing, which is lacking for environments with heterogenous input configurations) and made the protocol aware of the underlying hardware (which it deliberately has been designed not to be), it would be great for implementing the backend side of display server. – datenwolf Sep 01 '14 at 19:22
  • @ datenwolf, you know a way more than I about wayland. Last year I started to write a windows manager and UI lib for linux from scratch with Xlib and cairo mostly. I stopped it when I read that X should be replaced by wayland... you know I don't want work for months, even years on something and when ready to don't be able to use it because Xlib would be replaced... Today I using a personnal-hacked version of JWM... – The Unholy Metal Machine Sep 01 '14 at 19:35
  • @bob-thetrashygravedigger: Personally I believe that X will be around yet for a looong time (its backed by over 25 years of development and maintenance); there's just too much legacy applications out there that demand it. There's Xwayland as the "main" compatibility project, but I know (by personal word of mouth from the guys doing it) that a few guys are working on something really awesome that will bring Wayland apps and X11 together. You should not use Xlib, but only because Xlib is terribly broken. Use Xcb instead. And the most serious issues are actually issues of X.org not X11. – datenwolf Sep 01 '14 at 20:10
  • thx for that discussion, I have the feeling it would be instructive for me to talk more with you. NB : googling XCB, I got a naked girl in the google pictures... – The Unholy Metal Machine Sep 01 '14 at 20:17
  • @bob-thetrashygravedigger: NSFW content googling for Xcb, we've definitely got very different search histories; xcb.freedesktop.org is the first hit, when I search it. On second thought, my social life is close to zero, so that's that :) – datenwolf Sep 01 '14 at 21:21
  • social life ? what is this ? playing to sims 2 ? I'm sure I have less social activities than you... I'm a metalhead and I listen black metal sometime... I love quantum mechanic... I know well the libraries around my place (and then know me well too) but I don't know any theatre... you see... everything that "beautiful people" try to avoid... anyway, comming here talking/writing to people is a form of social activity... and it sound still better than taking his feet in picture ten times per day and uploading the pictures on a socialwebsite... ok I stop talking about my life, was funny somehow – The Unholy Metal Machine Sep 01 '14 at 21:34