0

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 perfectly 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();
...
}

Note: 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.

1 Answer 1

0

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
{
...
}

OR you can simply use protected QOpenGLExtraFunctions.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.