Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Create a Core Profile OpenGL app

    General and Desktop
    2
    3
    688
    Loading More Posts
    • 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.
    • ?
      A Former User last edited by A Former User

      Hi,

      I want to create an OpenGL app with Qt but my code segfault (11) on mac. My code is very short. The same code works with OpenGL 2.1.

      #include <GL/glew.h>                                   
      #include <iostream>                                    
                                                             
      #include <QApplication>                                
      #include <QOpenGLWidget>                               
                                                             
      int main(int argc, char** argv){          
              QApplication app(argc, argv);                  
                                                             
              QSurfaceFormat format;                         
              format.setMajorVersion(3);                     
              format.setMinorVersion(2);                     
              format.setProfile(QSurfaceFormat::CoreProfile);
                                                             
              QOpenGLWidget opengl;                          
              opengl.setFormat(format);                      
              opengl.setGeometry(30, 30, 600, 600);          
              opengl.show();                                 
                                                             
              return app.exec();                             
      }                                                      
      

      [EDIT]: I just test on Windows and it's works. What is the problem with mac ?

      Best regards,
      Robin

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User last edited by A Former User

        Ok I found the solution. I suppose mac use only the default opengl surface.
        I juste change my code like that: QSurfaceFormat::setDefaultFormat( format );

        Tell me why if you know :)

        1 Reply Last reply Reply Quote 0
        • T
          Thoenu last edited by

          Hi,
          OSX only supports OpenGL 4.1. Core Profile and Compatibility mode (means only 4.1. Specification works). Compatibility Mode is only supported until OpenGL 2.1. So for me it works this way:

          #ifdef APPLE
          format.setVersion(4, 1);
          format.setProfile(QSurfaceFormat::CoreProfile);
          #else
          format.setVersion(4, 5);
          format.setProfile(QSurfaceFormat::CompatibilityProfile);
          #endif
          QSurfaceFormat::setDefaultFormat(format);

          1 Reply Last reply Reply Quote 0
          • First post
            Last post