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.");
    glfwTerminate();
    }

    glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);

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

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

    glfwMakeContextCurrent(TempWindow);

    glewExperimental = GL_TRUE;

    GLenum err = glewInit();

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

    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":http://doc.qt.io/qt-5/qopenglcontext.html#create, get a "format":http://doc.qt.io/qt-5/qopenglcontext.html#format of it and check "majorVersion":http://doc.qt.io/qt-5/qsurfaceformat.html#majorVersion and "minorVersion":http://doc.qt.io/qt-5/qsurfaceformat.html#minorVersion


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.