Qt 5.7 OpenGL Core Profile > 2.1 on OS X - functions don't work



  • Hi,

    I'm working on an Early-2015 Macbook Pro, Intel Iris 6100 graphics, with Qt 5.7

    I've got some rendering code that previously used OpenGL ES 2.0 under Qt 5.5. I'd like to use some more advanced OpenGL functionality (texture buffers, texelFetch(), integer vertex attributes). I'm now working with Qt 5.7 compiled with -opengl desktop. When I request an OpenGL profile > 2.1, I always get 4.1 Core. However, if I use the glClearColor() and glClear() functions from QOpenGLFunctions_4_1_Core to just try to clear the screen to red, I just get black. Requesting 2.1 and using QOpenGLFunctions_2_1 gets me the desired red screen. A minimal (non) working example is below, with a CMake file.

    I get this message requesting 4.1 Core "QCocoaGLContext: Falling back to unshared context." The message is from this file: qcocoaglcontext.mm. However, I don't get the message indicating that a native context could not be created.

    Any thoughts on what might be going wrong? Apple's site says OpenGL 4.1 should be no problem.

    Thanks

    CMakeLists.txt

    cmake_minimum_required(VERSION 2.9)
    
    find_package(Qt5Gui REQUIRED)
    find_package(Qt5OpenGL REQUIRED)
    find_package(Qt5Widgets REQUIRED)
    
    add_executable(window example.cc)
    qt5_use_modules(window Gui OpenGL Widgets)
    

    example.cc

    #include <QApplication>
    #include <QOpenGLWidget>
    #include <QOpenGLFunctions_2_1>
    #include <QOpenGLFunctions_4_1_Core>
    #include <QSurfaceFormat>
    #include <QTimer>
    #include <QKeyEvent>
    
    #include <iostream>
    using std::cout;
    using std::endl;
    
    #if 0
      #define OGLFunctions QOpenGLFunctions_2_1
      #define REQUESTED_GL_MAJOR_VERSION 2
      #define REQUESTED_GL_MINOR_VERSION 1
      #define REQUESTED_GL_PROFILE QSurfaceFormat::NoProfile
    #else
      #define OGLFunctions QOpenGLFunctions_4_1_Core
      #define REQUESTED_GL_MAJOR_VERSION 4
      #define REQUESTED_GL_MINOR_VERSION 1
      #define REQUESTED_GL_PROFILE QSurfaceFormat::CoreProfile
    #endif
    
    class Window : public QOpenGLWidget, OGLFunctions
    {
    public:
      Window();
    protected:
      void initializeGL();
      void paintGL();
      void resizeGL(int w, int h);
    };
    
    int main(int argc, char** argv)
    {
      QApplication app(argc, argv);
      
      Window w;
      w.show();
    
      return app.exec();
    }
    
    Window::Window()
    {
      QSurfaceFormat sf;
      sf.setVersion(REQUESTED_GL_MAJOR_VERSION,
                    REQUESTED_GL_MINOR_VERSION);
      sf.setProfile(REQUESTED_GL_PROFILE);
      setFormat(sf);
    }
    
    void
    Window::initializeGL()
    {
      bool funcsInitOK = initializeOpenGLFunctions();
      cout << "OpenGL Functions Initialized OK: " << funcsInitOK << endl;
    
      // Get the surface format from the current context, and print the 
      // major and minor version actually received, along with the profile.
      QSurfaceFormat sf = QOpenGLContext::currentContext()->format();
      cout << "OpenGL Version: " << sf.majorVersion() << "."
           << sf.minorVersion() << endl;
      cout << "OpenGL Profile: ";
      switch(sf.profile())
      {
      case QSurfaceFormat::NoProfile:
        cout << "None";
        break;
      case QSurfaceFormat::CoreProfile:
        cout << "Core";
        break;
      case QSurfaceFormat::CompatibilityProfile:
        cout << "Compatibility";
        break;
      default:
        cout << "invalid option";
        break;
      }
      cout << endl;
      
      // If the functions work, clear the screen to red.
      glClearColor(1.0, 0.0, 0.0, 1.0);
    }
    
    void
    Window::paintGL()
    {
      glClear(GL_COLOR_BUFFER_BIT);
    }
    
    void
    Window::resizeGL(int w, int h)
    {
      // nothing for now.
    }
    
    

Log in to reply
 

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