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 Updated to NodeBB v4.3 + New Features

OpenGL 3.x Mac Lion

Scheduled Pinned Locked Moved General and Desktop
17 Posts 7 Posters 19.1k Views 1 Watching
  • 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.
  • 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