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. Create a Core Profile OpenGL app

Create a Core Profile OpenGL app

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 878 Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    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
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      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
      0
      • T Offline
        T Offline
        Thoenu
        wrote on last edited by
        #3

        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
        0

        • Login

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