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
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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.