Important: Please read the Qt Code of Conduct -

Getting OpenGL information before initializing OpenGL ...

  • Hello,

    I am looking for a way to get the "state" of OpenGL on the system that is running my application to better optimize the OpenGL experience that my application creates.

    So, take a look at the code below. With using GLFW, I can get the Major/Minor versions of OpenGL on the client system as well as the maximum number of samples that I can perform anti-aliasing on.

    I do this so that I can dynamically choose, at runtime, which shaders I need to load as I have different shaders based on the OpenGL version that is on the client system.

    What I am looking for is a pure Qt way of doing this; as it stands I have multiple unnecessary dependencies on GLFW and other libraries which creates bloat on my application.

    Any help appreciated!

    Thank you for your time.

    if (!glfwInit())
    fprintf(stderr, "GLFW failed to initialize.");

    glfwWindowHint(GLFW_VISIBLE, GL_FALSE);

    TempWindow = glfwCreateWindow(10, 10, "Checking OpenGL Version ...", NULL, NULL);

    if (!TempWindow)
    fprintf(stderr, "Could not determine OpenGL version; exiting.");


    glewExperimental = GL_TRUE;

    GLenum err = glewInit();

    if (err != GLEW_OK)
    fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
    fprintf(stderr, "Failed to initialize GLEW; exiting...");

    GLint MajorVersion;

    glGetIntegerv(GL_MAJOR_VERSION, &MajorVersion);

    GLint MinorVersion;

    glGetIntegerv(GL_MINOR_VERSION, &MinorVersion);

    GLint MaxSamples;

    glGetIntegerv(GL_MAX_SAMPLES, &MaxSamples);

  • Moderators

    You don't need a window for that. All you need is a valid OpenGL context. You can create a default one with "QOpenGLContext::create":, get a "format": of it and check "majorVersion": and "minorVersion":

Log in to reply