Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

question about QOpenGLWidget



  • hello, I try to use Qopenglwidget and glew to draw a triangle, but nothing comes out, what's wrong with the code, what I need to change? Is it ok to use glew+QOpenGLWiget? If it's possible, what I need to do with the code? I wish to work with glew + qopenglwidget. I saw other people draw sth with glew+QGLWidget, but QGLWidget is belong to QT4.8, QT5.4 seems throw it away.

    +++++++++++++++++++
    MeGlWindow.h
    #include <QOpenGLWidget>
    class MeGlWindow : public QOpenGLWidget
    {
    protected:
    void paintGL();
    void initializeGL();
    public:
    };
    ++++++++++++++++

    ++++++++++++++++
    MeGlWindow.cpp
    #include <gl/glew.h>
    #include "MeGlWindow.h"
    void MeGlWindow::initializeGL()
    {
    glewInit();
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GLfloat verts[]=
    {
    +0.0f,+1.0f,
    -1.0f,-1.0f
    +1.0f,-1.0f,
    };
    GLuint myBufferID;
    glGenBuffers(1, &myBufferID);
    glBindBuffer(GL_ARRAY_BUFFER, myBufferID);
    glBufferData(GL_ARRAY_BUFFER,sizeof(verts), verts, GL_STATIC_DRAW);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,0);

    }
    void MeGlWindow::paintGL()
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glDrawArrays(GL_TRIANGLES, 0,3);
    }
    +++++++++++++++

    +++++++++++++++
    main.cpp
    #include <QApplication>
    #include <QtGui/QGuiApplication>
    #include "MeGlWindow.h"
    int main(int argc, char** argv)
    {
    QApplication app(argc, argv);
    MeGlWindow meWindow;
    meWindow.resize(1024, 720);
    meWindow.show();
    return app.exec();
    }
    +++++++++++++++++++


  • Lifetime Qt Champion

    Hi,

    QGLWidget is deprecated but is still usable. As for QOpenGLWidget you can remove glew and use QOpenGLFunctions

    Hope it helps


Log in to reply