Reputation:
I am using the Qt Creator IDE and the Qt 5.7 framework for my program. I have a widget in my form. This widget is controlled by OpenGL. To be more specific, I want to draw shapes with OpenGL on that widget. However, I can't use glGenVertexArrays or glBindVertexArray. I get 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
Upvotes: 1
Views: 1284
Reputation: 22816
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:
OES_
extension, or on Apple devices where you got the APPLE_
extension).Upvotes: 4