Create a Core Profile OpenGL app



  • 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



  • 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 :)



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


Log in to reply
 

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