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. OpenGL 3.x Mac Lion
Forum Update on Monday, May 27th 2025

OpenGL 3.x Mac Lion

Scheduled Pinned Locked Moved General and Desktop
17 Posts 7 Posters 19.0k 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.
  • J Offline
    J Offline
    jmacey
    wrote on last edited by
    #1

    Hi,

    I've just updated to Lion and the program GLView view indicates that OpenGL 3.2 is 100% supported, however it seems by default only glsl #version 120 is enabled and GL 2.x.

    I've used the following code to try and enable GL core profile

    @GLFormat fmt;
    fmt.setProfile(QGLFormat::CoreProfile);
    fmt.setVersion(3,2);
    fmt.setSampleBuffers(true);
    fmt.setSamples(4);
    QGLFormat::setDefaultFormat(fmt);@

    and the query of the formats reports
    GL Version 3.2
    Using profile 1

    as expected. However once I create the open gl contex and run the following code

    @ std::cout<<"Version "<<glGetString(GL_VERSION)<<"\n";
    std::cout<<"GLSL "<<glGetString(GL_SHADING_LANGUAGE_VERSION)<<"\n";
    @

    I get

    Version 2.1 NVIDIA-7.2.9
    GLSL 1.20

    Is the higher version of GL supported in Mac yet? If not where would be the best place in the source tree for me to look to enable it, I've found this post http://lwjgl.org/forum/index.php?topic=4071.0 so I guess I could hack some of the source to get it working.

    I really need glsl 150 as I develop for mac linux and windows.

    cheers

    Jon

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      If you think that a patch for Qt is needed, feel free to open a bug report. I'm not sure Lion will be already supported in 4.8.

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jmacey
        wrote on last edited by
        #3

        Not sure it's a bug as such just a lack of feature for the new version of OpenGL. According to the new version of glview 3.2 is supported but I'm presuming it's just not activated in the current qtgl library as it's so new. I will download the source and drill into the lib to see where the context in the QGLWidget is created and see if I can patch it.

        If anyone knows a good place to start let me know.

        It will be good to be able to convert all my code to
        Glsl 150 as I won't have to support separate shaders for mac vs Linux and windows for next years teaching.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #4

          src/opengl/qgl_mac.mm sounds like a good place to start :)

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jmacey
            wrote on last edited by
            #5

            cheers, downloading the 4.8 beta for a test then will get the source and have a play

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jmacey
              wrote on last edited by
              #6

              it seems that Qt 4.8 Beta gives me the core profile under Lion ;-) however Lion has two drivers (compatibility and core) the compat is 2.0 only so I just need to remove a few deprecated functions from my library first.

              For more details on the Mac GL this is good http://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&p=104206#104206

              Thanks for the help

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jmacey
                wrote on last edited by
                #7

                spoke too soon, seem I had some legacy Mac code in my initializeGL function, the driver is initialsed and reports 3.2 but the context isn't created to the same so get crashes, oh well. Will download the 4.7 source and hack

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mcdi
                  wrote on last edited by
                  #8

                  In case if it is still actual topic. Here is some code, which allows to get opengl 3.2 core without hacking Qt4.7.

                  test_ogl_core_context.cpp:
                  @
                  #include <QApplication>

                  #include <QGLWidget>
                  #include <QGLContext>

                  #include <iostream>

                  void* select_3_2_mac_visual(GDHandle handle);

                  struct Core3_2_context : public QGLContext
                  {
                  Core3_2_context(const QGLFormat& format, QPaintDevice* device) : QGLContext(format,device) {}
                  Core3_2_context(const QGLFormat& format) : QGLContext(format) {}

                  virtual void* chooseMacVisual(GDHandle handle)
                  

                  {
                  return select_3_2_mac_visual(handle);
                  }
                  };

                  struct OglWidget : public QGLWidget
                  {
                  OglWidget() : QGLWidget(new Core3_2_context(QGLFormat::defaultFormat()))
                  {
                  }
                  virtual void initializeGL()
                  {
                  std::cout<<glGetString(GL_VERSION)<<std::endl;
                  }
                  virtual void paintGL()
                  {
                  glClearColor(0,1,0,1);
                  glClear(GL_COLOR_BUFFER_BIT);
                  }
                  };

                  int main(int argc, char *argv[])
                  {
                  QApplication app(argc,argv);

                  OglWidget w;
                  w.show();

                  return app.exec();
                  }
                  @

                  core_profile_attributes.mm:
                  @
                  #include <QGLContext>

                  void* select_3_2_mac_visual(GDHandle handle)
                  {
                  static const int Max = 40;
                  NSOpenGLPixelFormatAttribute attribs[Max];
                  int cnt = 0;

                  attribs[cnt++] = NSOpenGLPFAOpenGLProfile;
                  attribs[cnt++] = NSOpenGLProfileVersion3_2Core;
                  
                  attribs[cnt++] = NSOpenGLPFADoubleBuffer;
                  
                  attribs[cnt++] = NSOpenGLPFADepthSize;
                  attribs[cnt++] = (NSOpenGLPixelFormatAttribute)16;
                  
                  attribs[cnt] = 0;
                  Q_ASSERT(cnt < Max);
                  
                  
                  return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
                  

                  }
                  @

                  CMakeLists.txt:
                  @
                  PROJECT(qt4_lion_ogl32)
                  cmake_minimum_required(VERSION 2.8)

                  FIND_PACKAGE(Qt4)
                  SET( QT_USE_QTOPENGL true )
                  INCLUDE( ${QT_USE_FILE} )

                  FIND_PACKAGE(OpenGL)

                  ADD_EXECUTABLE( test_ogl_core_context
                  #test_ogl_core_context.cpp
                  core_profile_attributes.mm
                  )
                  TARGET_LINK_LIBRARIES( test_ogl_core_context
                  ${QT_LIBRARIES}
                  ${OPENGL_LIBRARIES}
                  "-framework Foundation"
                  "-framework Cocoa"
                  )
                  @

                  Sorry, if it is written not in the best way. I am new for Mac.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jmacey
                    wrote on last edited by
                    #9

                    Thanks will give it a go

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jmacey
                      wrote on last edited by
                      #10

                      Just to say I've finally got back from Holiday and integrated your code with my own and it works, thanks mcdi really useful. Will write up a full blog report / post soon and add a link here as got basic Qt + OpenGL 3.x and glsl 150 working on the mac

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        tomato
                        wrote on last edited by
                        #11

                        It worked like a charm, pure "core profile"! Thanks a lot mcdi!
                        For noobs on mac platform, like me, here is the trick for mixing objective-C directly in .pro file :
                        @ mac {
                        OBJECTIVE_SOURCES += core_profile_attributes.mm
                        LIBS += -framework Foundation -framework Cocoa
                        }@
                        "source":http://el-tramo.be/blog/mixing-cocoa-and-qt

                        お前はもう死んでいる

                        1 Reply Last reply
                        0
                        • Z Offline
                          Z Offline
                          ZapB
                          wrote on last edited by
                          #12

                          Not sure about mac as I have no way to test but support for getting an OpenGL Core profile context has been added to 4.8.0 in gitorious. See this "post":http://developer.qt.nokia.com/forums/viewthread/4856/P15/#30548

                          Nokia Certified Qt Specialist
                          Interested in hearing about Qt related work

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            miketopen
                            wrote on last edited by
                            #13

                            Hi everyone,
                            I tried to create a openGL 3.2 core context on my mac (mountain lion) with qt 4.8.3 and it was not possible....

                            Fortunately, when using the code above it was working! :-) A very helpful thread....

                            The .pro-file is simply for completeness here:

                            opengl3_and_qt.pro
                            @
                            QT += core gui opengl

                            TARGET = opengl3_and_qt
                            TEMPLATE = app

                            SOURCES += test_ogl_core_context.cpp
                            OBJECTIVE_SOURCES += core_profile_attributes.mm
                            LIBS += -framework Foundation -framework Cocoa
                            @

                            Now the question: is there an other and more clean way on the mac with qt to create an opengl 3.2 context??

                            Thanks

                            Mike
                            

                            www.topen.org

                            1 Reply Last reply
                            0
                            • Z Offline
                              Z Offline
                              ZapB
                              wrote on last edited by
                              #14

                              OpenGL 3.2 Core Profile should work out of the box on OS X with Qt5 now.

                              Nokia Certified Qt Specialist
                              Interested in hearing about Qt related work

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                miketopen
                                wrote on last edited by
                                #15

                                [quote author="ZapB" date="1352755393"]OpenGL 3.2 Core Profile should work out of the box on OS X with Qt5 now.[/quote]

                                I tried to use the core profile on Mountain Lion with Qt 5.0.0, but it seems not to work. Does anyone has an working example (on OSX) with OpenGL 3.2 and Core Profile? All the OpenGL examples shipped with Qt are using OpenGL 2.

                                Thanks in advance

                                Mike

                                p.s. If there is a special git version of Qt I have to use I'm also fine with that.

                                www.topen.org

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  miketopen
                                  wrote on last edited by
                                  #16

                                  Hi

                                  I think I have to restate my sentence about "openGL 3.2 is not working". Actual it is working out of the box, but I used the "wrong" example. I tried it with this "tutorial":http://qt-project.org/wiki/How_to_use_OpenGL_Core_Profile_with_Qt unfortunately for Qt 5 the wrong headers are used, and then it is indeed not work....but this (shame to myself) is also written in the Qt documentation. However, after fixing the headers the simple example was working :-)

                                  For the people interested I put the adopted variant "here":https://github.com/mikenicolai/qt5-opengl3-examples

                                  Bests

                                  Mike
                                  

                                  www.topen.org

                                  1 Reply Last reply
                                  0
                                  • E Offline
                                    E Offline
                                    eyetracker
                                    wrote on last edited by
                                    #17

                                    Hi all,

                                    I tried the above solution as well as the 07-core-profile from the wiki
                                    "here":http://qt-project.org/wiki/How_to_useOpenGL_Core_Profile_with_Qt</a>, but on OS X 10.8.4, Qt 4.8.4 still won't budge out of GL version 2.1 with GLSL version 1.20. Here's the output from the above solution (with most of the shader stuff commented since the compiler was complaining about QOpenGLBuffer which I thought might be specific to Qt 5).

                                    The output I get is:

                                    Widget OpenGl: 1.0
                                    Context valid: 1
                                    Really used OpenGl: 1.0
                                    OpenGl information: VENDOR: NVIDIA Corporation
                                    RENDERDER: NVIDIA Quadro K5000 OpenGL Engine
                                    VERSION: 2.1 NVIDIA-8.12.47 310.40.00.05f01
                                    GLSL VERSION: 1.20

                                    Any ideas what I might be missing? The 07-core-profile wiki entry has a bold comment about some OS X "issues" but I didn't see what those issues were or their resolution.

                                    This started with me trying to use textureSize in a shader which should be supported under Mountain Lion (GLView app shows GL version 3.2 along with the Quadro K5000 NVidia driver as identified above).

                                    Thanks!

                                    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