Important: Please read the Qt Code of Conduct -

OpenGL 3.x Mac Lion

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

    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 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.



  • 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.

  • 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.

  • src/opengl/ sounds like a good place to start :)

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

  • 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

    Thanks for the help

  • 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

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

    #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()
    virtual void paintGL()

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

    OglWidget w;;

    return app.exec();
    #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];


    cmake_minimum_required(VERSION 2.8)



    ADD_EXECUTABLE( test_ogl_core_context
    TARGET_LINK_LIBRARIES( test_ogl_core_context
    "-framework Foundation"
    "-framework Cocoa"

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

  • Thanks will give it a go

  • 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

  • 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 {
    LIBS += -framework Foundation -framework Cocoa

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

  • 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:
    QT += core gui opengl

    TARGET = opengl3_and_qt
    TEMPLATE = app

    SOURCES += test_ogl_core_context.cpp
    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??



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

  • [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


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

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



  • Hi all,

    I tried the above solution as well as the 07-core-profile from the wiki
    "here":</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).


Log in to reply