簡體   English   中英

找不到Qt Creator Qt 5.7 OpenGL函數

[英]Qt Creator Qt 5.7 OpenGL Functions not found

我在程序中使用Qt creator ide和Qt 5.7框架。 我的表單中有一個小部件。 此小部件由opengl控制。 更具體地說,我想在該小部件上使用opengl繪制形狀。 但是我不能使用glGenVertexArrays,glBindVertexArray。 我收到這些錯誤:

'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文件

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

與頂點數組相關的函數不在QOpenGLFunctions ,因為該類針對的是OpenGL 2.1(+ FBO)和OpenGL ES 2的公共子集。

它們可以通過其他方式使用:

  • QOpenGLExtraFunctions(針對GL 3.x +擴展名/ ES 3.x)
  • QOpenGLVertexArrayObject(該功能的包裝器類)
  • QOpenGLExtension_ARB_vertex_array_object(僅包裝相應的擴展名。這不適用於ES 2(具有OES_擴展名)或Apple設備(具有APPLE_擴展名)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM