I'm trying to port my old Qt/OpenGL game from Linux to Windows.
I'm using Qt Creator.
It compiled fine right away but gave a lot of errors like undefined reference to 'glUniform4fv@12'
at linking stage.
I've tried to link more libs -lopengl32 -lglaux -lGLU32 -lglut -lglew32
but it gave the same result.
Qt also uses -lQt5OpenGLd
by default.
I'm including QGLWIdget with :
#define GL_GLEXT_PROTOTYPES
#include <QGLWidget>
I've also tried using GLEW but it confilcts with Qt (or QOpenGL?).
How can I get rid of those undefined references? Is there any other library that i have to link to?
Thanks in advance.
Tomxey
Windows doesn't provide the prototypes of any OpenGL function introduced after OpenGL 1.1. You must resolve the pointers to those functions at runtime (via
GetProcAddress
-- or betterQOpenGLContext::getProcAddress
, see below).Qt offers excellent enablers to ease this job:
QOpenGLShader
andQOpenGLShaderProgram
allow you manage your shaders, shader programs, and their uniforms. QOpenGLShaderProgram provides nice overloads allowing you to seamlessly passQVector<N>D
orQMatrix<N>x<N>
classes:QOpenGLContext::getProcAddress()
is a platform-independent function resolver (useful in combination withQOpenGLContext::hasExtension()
to load extension-specific functions)QOpenGLContext::functions()
returns a QOpenGLFunctions object (owned by the context), which offers as public API the common subset between OpenGL 2 (+FBO) / OpenGL ES 2.¹ It will resolve the pointers behind the scenes for you, so all you have to do is callingQOpenGLContext::versionFunctions<VERSION>()
will return aQAbstractOpenGLFunctions
subclass, namely, the one matching theVERSION
template parameter (or NULL if the request can't be satisfied):As an alternative way, you can make your "drawing" classes /inherit/ from
QOpenGLFunctionsX
. You can initalize them as usual, but this way you can keep your code like:¹ There are also "matching" classes in the
QtOpenGL
module, i.e.QGLContext
andQGLFunctions
. If possible, avoid usingQtOpenGL
in new code, as it's going to be deprecated in a couple of releases in favour of theQOpenGL*
classes.