July 23, 2011

jmacey jmacey
Lab Rat
24 posts

OpenGL 3.x Mac Lion

Page  
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

  1. GLFormat fmt;
  2. fmt.setProfile(QGLFormat::CoreProfile);
  3. fmt.setVersion(3,2);
  4. fmt.setSampleBuffers(true);
  5. fmt.setSamples(4);
  6. 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

  1.  std::cout<<"Version "<<glGetString(GL_VERSION)<<"\n";
  2. 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

16 replies

July 23, 2011

peppe peppe
Ant Farmer
1028 posts

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.

 Signature 

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

July 23, 2011

jmacey jmacey
Lab Rat
24 posts

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.

July 23, 2011

peppe peppe
Ant Farmer
1028 posts

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

 Signature 

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

July 23, 2011

jmacey jmacey
Lab Rat
24 posts

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

July 23, 2011

jmacey jmacey
Lab Rat
24 posts

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

July 23, 2011

jmacey jmacey
Lab Rat
24 posts

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

July 28, 2011

mcdi mcdi
Lab Rat
1 posts

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:

  1. #include <QApplication>
  2.  
  3. #include <QGLWidget>
  4. #include <QGLContext>
  5.  
  6. #include <iostream>
  7.  
  8. void* select_3_2_mac_visual(GDHandle handle);
  9.  
  10.  
  11. struct Core3_2_context : public QGLContext
  12. {
  13.  Core3_2_context(const QGLFormat& format, QPaintDevice* device) : QGLContext(format,device) {}
  14.  Core3_2_context(const QGLFormat& format) : QGLContext(format) {}
  15.  
  16.     virtual void* chooseMacVisual(GDHandle handle)
  17.  {
  18.   return select_3_2_mac_visual(handle);
  19.  }
  20. };
  21.  
  22. struct OglWidget : public QGLWidget
  23. {
  24.  OglWidget() : QGLWidget(new Core3_2_context(QGLFormat::defaultFormat()))
  25.  {
  26.  }
  27.  virtual void initializeGL()
  28.  {
  29.   std::cout<<glGetString(GL_VERSION)<<std::endl;
  30.  }
  31.  virtual void paintGL()
  32.  {
  33.   glClearColor(0,1,0,1);
  34.   glClear(GL_COLOR_BUFFER_BIT);
  35.  }
  36. };
  37.  
  38. int main(int argc, char *argv[])
  39. {
  40.  QApplication app(argc,argv);
  41.  
  42.  OglWidget w;
  43.  w.show();
  44.  
  45.  return app.exec();
  46. }

core_profile_attributes.mm:

  1. #include <QGLContext>
  2.  
  3.  
  4. void* select_3_2_mac_visual(GDHandle handle)
  5. {
  6.     static const int Max = 40;
  7.     NSOpenGLPixelFormatAttribute attribs[Max];
  8.     int cnt = 0;
  9.    
  10.     attribs[cnt++] = NSOpenGLPFAOpenGLProfile;
  11.     attribs[cnt++] = NSOpenGLProfileVersion3_2Core;
  12.    
  13.     attribs[cnt++] = NSOpenGLPFADoubleBuffer;
  14.    
  15.     attribs[cnt++] = NSOpenGLPFADepthSize;
  16.     attribs[cnt++] = (NSOpenGLPixelFormatAttribute)16;
  17.    
  18.     attribs[cnt] = 0;
  19.     Q_ASSERT(cnt < Max);
  20.    
  21.  
  22.     return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
  23. }

CMakeLists.txt:

  1. PROJECT(qt4_lion_ogl32)
  2. cmake_minimum_required(VERSION 2.8)
  3.  
  4. FIND_PACKAGE(Qt4)
  5. SET( QT_USE_QTOPENGL true )
  6. INCLUDE( ${QT_USE_FILE} )
  7.  
  8. FIND_PACKAGE(OpenGL)
  9.  
  10.  
  11. ADD_EXECUTABLE( test_ogl_core_context
  12.     #test_ogl_core_context.cpp
  13.     core_profile_attributes.mm
  14. )
  15. TARGET_LINK_LIBRARIES( test_ogl_core_context
  16.   ${QT_LIBRARIES}
  17.   ${OPENGL_LIBRARIES}
  18.   "-framework Foundation"
  19.   "-framework Cocoa"
  20. )

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

July 31, 2011

jmacey jmacey
Lab Rat
24 posts

Thanks will give it a go

August 15, 2011

jmacey jmacey
Lab Rat
24 posts

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

September 21, 2011

tomato tomato
Lab Rat
9 posts

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 :

  1.  mac {
  2.      OBJECTIVE_SOURCES  +=  core_profile_attributes.mm
  3.      LIBS += -framework Foundation -framework Cocoa
  4.  }

source [el-tramo.be]

 Signature 

お前はもう死んでいる

October 13, 2011

ZapB ZapB
Ant Farmer
1425 posts

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 [developer.qt.nokia.com]

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

November 11, 2012

miketopen miketopen
Lab Rat
25 posts

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

  1. QT       += core gui opengl
  2.  
  3. TARGET = opengl3_and_qt
  4. TEMPLATE = app
  5.  
  6. SOURCES +=  test_ogl_core_context.cpp
  7. OBJECTIVE_SOURCES  +=  core_profile_attributes.mm
  8. 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
 Signature 

www.topen.org

November 12, 2012

ZapB ZapB
Ant Farmer
1425 posts

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

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

January 29, 2013

miketopen miketopen
Lab Rat
25 posts
ZapB wrote:
OpenGL 3.2 Core Profile should work out of the box on OS X with Qt5 now.

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.

 Signature 

www.topen.org

February 23, 2013

miketopen miketopen
Lab Rat
25 posts

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 [qt-project.org] 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 [github.com]

Bests

Mike
 Signature 

www.topen.org

Page  
1

  ‹‹ [Solved] Making filter in QTableWidget      Barcode generation on Windows and Linux [Solved] ››

You must log in to post a reply. Not a member yet? Register here!