Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting OpenGL information before initializing OpenGL ...

Getting OpenGL information before initializing OpenGL ...

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tmason101
    wrote on last edited by
    #1

    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);
    @

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved