Nominate our 2022 Qt Champions!

OpenGL with shaders in QT4 or 5 on windows

  • Hi,
    I'm trying to get OpenGL working with QT 5 on windows. I have similar code working on Linux just fine but on Windows using visual studio, I've had troubles for days with linker errors and have run out of ideas.

    Specifically, when trying to use shader related functions like 'glCreateProgram()', I get linker errors (cannot find *_*glCreateProgram()). I am linking against opengl32.lib and Qt5OpenGL.lib.

    Also, I cannot find an opengl template application when trying to create a test project in QT5 so I haven't got anything canonical to test against.

    I should add that I need the opengl functions where they should be, in the global namespace as this code is shared between Qt and non Qt projects - this seems to be a problem as the QGLFunctions is in its own namespace.

    Has anybody else got this working in QT5 on windows in this way?

  • I've managed to get this to work but in a rather tortuous way which doesn't feel right. Calling the gl functions in the same scope as a QGLFunctions object works out of the box - fine if you're developing Qt applications from scratch and all your GL calls are within that object. I need those functions in global scope so I had to write a wrapper around all the gl functions that points to the QGLFunctions object. Like I said, it's not a nice solution but it does appear to work.

  • Windows only exports symbols for OpenGL <=1.1. All other gl functions have to be resolved dynamically at run time. This is what QOpenGLFunctions and the new set of QOpenGLFunctions_<MAJOR>_<MINOR>[_PROFILE] classes do for you. Once you have obtained and initialized such a function object just expose it somewhere convenient rather than calling global functions.

    There should be no need to link to libQt5OpenGL at all unless you are using QGLWidget. Linking to the opengl32.lib should be done for you as it is a dependency of QtGui.

Log in to reply