OpenGL 3.2 core profile, QT 4.8 RC1 not working on Windows and Mac

  • I followed ZapB's "article": but I’m running into problems in creating an OpenGL 3.2 core profile context on both Windows and Mac Lion using the Qt 4.8 RC 1 from 13th Oct.

    On Windows 7 64bit I get a buffer overflow during the QGLExtensionMatcher … the 2nd time “m_offsets << m_extensions.size();” is called to be exact.

    On Mac there is no OpenGL 3.2 context created. glFormat.majorVersion() << “.” << glFormat.minorVersion() gives me 2.1 (using this->format() inside a QGLWidget).
    There was another "thread": that created OpenGL 3.2 context using some Cocoa code on mac which I’ve tried that actually created the correct context but it isn’t recognized by Qt so I cant load a shader as it assumes I have a 2.1 context (Same version info from Qt while OpenGL tells me it’s 3.2). This means that it uses a pre-OpenGL-3 extension checker which leads to calling depracated functions and eventually failing to support any Shader.

    Is it just me? I’m trying this on 2 different machines btw. Any help is appreciated.

  • I rewrote the QGLShaderProgram, copied over the main functions and removed the extension-checking. The shader is loading/compiling/linking fine now on both platforms, no error here.

    The windows variant still produces a buffer overflow but in an untrackable area - somewhere in the mainloop (between initializeGL and paintGL).

    The mac version (using the mentioned Cocoa context creation) creates a window with just the background color and no triangle. It is the same program (openGL-wise) as in the article.

  • Hmmm, OK. I need to try this on Windows yet. Unfortunately I do not have access to any Macs on which to test.

    I'll take a look on windows when I get caught up from my DevDays backlog ;-)

  • the windows buffer-overflow problem even occurs when there's no actual OpenGL code inside the widget.

    Another Windows OpenGL 3.2 "example": works fine with nvidia driver 275.

  • The GL support on Mac OS X is rather poor and I haven't seen a Mac offering anything better than a 2.1 version of OpenGL. However you will find many of the new(er) GPU features exposed through the GL extensions system. I haven't tried OS X Lion but on 10.5 and 10.6 I have never been able to get a Core GL profile running.

  • Macs pre lion can only do max. Opengl 2.1
    Lion is the first to do either 2.1 or 3.2 core (at least thats how i understood it).

  • Did you check that your hardware actually supports it ?
    Run glxinfo on the command line to get your GL implementation version.

  • I ran the opengl extension checker...
    The hardware is a nvidia gtx 260 on windows and an ati 6970m hd on the current line imac. Both can do at least 3.2

    I was able to create a 3.2 core context without qt

  • Apologies for bumping an old post, but I am also experiencing this problem.

    I have Qt 4.8.0 RC installed and I am using a brand new Macbook Pro with OSX Lion which does have support for OpenGL 3.2 as seen on the "OpenGL capabilities table for Mac OSX Lion":

    I have tried to run the example written by ZapB and only changed the GLSL version to #150 and the errors are saying
    QGLShader::compile(Vertex): ERROR: 0:1: '' : version '150' is not supported

    "ERROR: 0:1: '' : version '150' is not supported
    QGLShader::compile(Fragment): ERROR: 0:1: '' : version '150' is not supported

    "ERROR: 0:1: '' : version '150' is not supported
    which simply is not true.

    I would be interested to know if there are any others who could reproduce this problem Mac and I would be most grateful for anyone who knows of a solution to this problem.

  • If u read out the OpenGL version you'll see the problem: I'm quite sure it'll be OpenGL 2.1 which doesn't support GLSL 1.5 - the error message is true in that way;)
    I fiddled around with the problem for some time but I wasn't able to create an OpenGL 3.2 Context in the QGLWidget.

    Here's my "solution":
    I wrote my own GLWidget, based on a QMacCocoaViewContainer. It contains a NSOpenGLView in which I create the 3.2 core profile context. The main access methods/callbacks are wrapped outside so it behaves pretty much like the QGLWidget - at least the functions I need (paint, resize, key/mouse events, initialize) are "forewarded".
    As the QGLShaderProgram uses Qt-internal version-testing methods to call the right functions for either OpenGL3 or OpenGL2, I also had to write my own implementation just for OpenGL3. The original class detected OpenGL 2.1 and made some wrong calls...

    All in all it was quite some work, but it's running quite nicely with OpenGL 3.2 context and GLSL 150 core shader. If the "real" QGLWidget gets fixed I should be able to just replace it and the ShaderProgram class.

    I found out that nvidia drivers behave quite differently and allow a lot of calls that are outside the OpenGL spec (running OpenGL 4.1 introduced functions inside an OpenGL 3.2 core context, allowing GLSL-functions that are deprecated, etc. ). I'd be intersting to know if anyone with a nvidia gfx and OSX Lion has problems with the QGLWidget and OpenGL 3.2...

  • Thanks for the reply. I see that you've put in quite a lot of effort to work around this problem. I too hope that this problem will be fixed soon. In the mean time I'll try implementing your method, or at least just stick with Windows for just a while longer.

  • Sorry to necropost. I am now able to reproduce the buffer overflow as mentioned by the OP. I have made a non-Qt windows OpenGL app that acquires an OpenGL 4.2 core profile context which works fine. So it appears that something is going wrong in the Qt context creation code.

    Is anybody able to reproduce this on an ATI card on windows? Although I suspect it is not a driver issue but just something else to rule out.

    I have stepped through the Qt OpenGL context creation code and from what I can see so far all appears to be fine. It creates a temporary context, resolves some function entry points, then creates a core profile context using the same options as my non-Qt app. Yes when it comes to call glGetStringi( GL_EXTENSIONS, i ); it seems that some sort of stack corruption is occurring as the debugger shows the value of "this" changing each time this function is called.

    I'll keep digging but if I can't resolve it soon I'll file a bug report.

  • I think I've also run into the buffer overflow (or at least stack corruption of some kind) in the call to glGetStringi. I suspect "this": is the same issue as well. Actually exactly the same problem was discussed in comments on the bug report which originally introduced this code, "QTBUG-11052": The fix was to add the missing APIENTRY macro to the qt_glGetStringi function pointer typedef (it makes sense that leaving this off would lead to stack corruption). However the APIENTRY wasn't included in the version of the code that was eventually commited in commit 2f59eaee. I've verified that adding the APIENTRY does fix the problem for me, but perhaps it causes problems on some platforms? (I'm on Win 7 64-bit with a GT545).

  • Well spotted! Thanks for the tip. I am on the road at the moment but will try this fix when I return home at the weekend. I'll post back here with the results. Thanks again!

  • The "fix for this":,16794 has been merged into Qt5 now. Next up I will cherry pick it for Qt 4.8 later today.

  • Was Mac giving you troubles? ;-)

  • Yeah. The way that APIENTRY macro is brought into play is slightly different in Qt5 and I never tried building it on Mac myself before my first attempt. My bad as I do actually have a MacBook now.

    /me must try harder ;-)

  • Hi ZapB,
    I am experiencing similar problems when trying to use the 3.2 core profile and GLSL 1.5 on Mac OSX Lion. How can I obtain the fix that you posted above(,16794)? Is this Windows specific?

    Will I have to wait for the release of Qt 5 or a patch for 4.8?

    Thanks in advance,

  • Hi Jason,

    that particular fix was to fix a stack corruption on Windows. My next task is to fix the OpenGL context creation code for Mac and Windows to actually allow use of a Core profile context - it works fine on Linux. I'll post back here when I have something usable but it may take me a few days as I am away on a course most of this week.

  • Hi ZapB,

    Are we getting any closed to this fix (use of a Core profile context in Mac) or has it been postponed further?

    Thanks in advance,

  • It is fixed in Qt5 already (see,22653). I've not had time to backport to 4.8.x yet. Still lots of work that could be done to improve using Core profile GL with Qt though.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.