Batın Evirgen Batın Evirgen - 3 months ago 34
C++ Question

Qt Creator Qt 5.7 OpenGL Functions not found

I am using Qt creator ide and Qt 5.7 framework for my program. And i have a widget in my form. This widget controlled by opengl. To be more specific, i want to draw shapes with opengl on that widget. But i can't use glGenVertexArrays, glBindVertexArray.
I got these errors:

'glGenVertexArrays': identifier not found
'glBindVertexArray': identifier not found


GLWidget.h:

#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QOpenGLWidget>
#include <QOpenGLFunctions>

class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
explicit GLWidget(QWidget *parent);

protected:
void initializeGL() Q_DECL_OVERRIDE;
void paintGL() Q_DECL_OVERRIDE;
void resizeGL(int w, int h) Q_DECL_OVERRIDE;
};

#endif // GLWIDGET_H


GLWidget.cpp

#include "glwidget.h"

GLWidget::GLWidget(QWidget *parent) : QOpenGLWidget(parent)
{

}

void GLWidget::initializeGL() {
initializeOpenGLFunctions();
glClearColor(0, 0, 0, 1);
}

void GLWidget::paintGL() {
GLuint VertextArrayID;
glGenVertexArrays(1, &VertextArrayID);
glBindVertexArray(VertextArrayID);
}

void GLWidget::resizeGL(int w, int h) {

}


.pro file

QT += core gui opengl

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = QtOpenGLTest
TEMPLATE = app

LIBS += -lOpenGL32
SOURCES += main.cpp\
mainwindow.cpp \
glwidget.cpp

HEADERS += mainwindow.h \
glwidget.h

FORMS += mainwindow.ui

Answer

Vertex arrays-related functions are not in QOpenGLFunctions, as that class aims at the common subset of OpenGL 2.1 (+FBO) and OpenGL ES 2.

They're available in other ways:

  • QOpenGLExtraFunctions (aiming at GL 3.x + extensions / ES 3.x)
  • QOpenGLVertexArrayObject (wrapper class for the functionality)
  • QOpenGLExtension_ARB_vertex_array_object (which just wrapper the corresponding extension. This won't work on ES 2, where you got the OES_ extension, or on Apple devices where you got the APPLE_ extension).
Comments