QOpenGLWidget - How to get OpenGL version from OS
-
I have noticed the QOpenGLWidget is sensitive to the OpenGL version that the operating system has. It appears that anything less than OpenGL 2.0 will not work (I was testing with OpenGL 1.4 and the console shows a number of shader compile errors then the program crashes when the QOpenGLWidget is first displayed).
It is possible to get the OpenGL version using the function glGetString(GL_VERSION) but this must be called when the rendering context is current. Using the QOpenGLWidget the earliest this can be checked is when the function initializeGL() is called following the call of initializeOpenGLFunctions(). At this point it is too late to prevent the program from blowing up.
I have created a dummy window with an OpenGL rendering context in order for me to run the command glGetString(GL_VERSION) but this has its own problems (not portable for one and it seems to interfear with QOpenGLWidget). This works (sort of) but is something I would like to avoid.
I am looking for a way to figure out what version of OpenGL the operating system is currently running so I can handle this properly in the program. If, for example, I can determine that the OpenGL version in the operating system is less than 2.0 I would disable these windows completely.
As an alternate is there any way to turn off the use of shaders in QOpenGLWidget ? They seem to be baked into this widget.
-
@kshegunov Thanks. That looks like it will work and be portable at the same time. What I was thinking was something along the same lines but I didn't realize you could create a rendering context without all the baggage of a complete window (although I suspect there is a lot going on in the background).
This is Chris Kawa's example for posterity:
int main(int argc, char *argv[]) { QApplication a(argc, argv); QOffscreenSurface surf; surf.create(); QOpenGLContext ctx; ctx.create(); ctx.makeCurrent(&surf); qDebug () << (const char*)ctx.functions()->glGetString(GL_VERSION); qDebug () << (const char*)ctx.functions()->glGetString(GL_EXTENSIONS); }