Qt5.10 Windows: Error: 'glVertexAttrib2fv' was not declared in this scope?
Solved
General and Desktop
-
I am trying to port my OpenGL project from GLFW to Qt 5.10.1 on Windows using MinGW but I am facing some issues. Everything was working perfect until I needed to use glVertexAttrib2fv which Qt says "was not declared in this scope"! I don't know what am I missing.
main.cpp
QSurfaceFormat format; format.setVersion(4, 3); format.setProfile(QSurfaceFormat::CoreProfile); format.setDepthBufferSize(24); format.setStencilBufferSize(8); format.setSamples(10); QSurfaceFormat::setDefaultFormat(format);
myopenglwidget.h:
#include <QWidget> #include <QOpenGLWidget> #include <QOpenGLFunctions_4_3_Core> #include <QOpenGLShaderProgram> class MyOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_4_3_Core { protected: void initializeGL(); ... } void MyOpenGLWidget::initializeGL() { // initialize OpenGL Functions initializeOpenGLFunctions(); ... }
glVertexAttrib2fv is supported in all versions of OpenGL: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glVertexAttrib.xhtml
Ask If more information is needed to solve this problem.
-
I found the solution, the trick was to use CompatibilityProfile rather than CoreProfile!
main.cpp
QSurfaceFormat format; format.setVersion(4, 3); format.setProfile(QSurfaceFormat::CompatibilityProfile); format.setDepthBufferSize(24); format.setStencilBufferSize(8); format.setSamples(10); QSurfaceFormat::setDefaultFormat(format);
myopenglwidget.h:
#include <QWidget> #include <QOpenGLWidget> #include <QOpenGLFunctions_4_3_Compatibility> #include <QOpenGLShaderProgram> class MyOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_4_3_Compatibility { ... }