Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. question about QOpenGLWidget
QtWS25 Last Chance

question about QOpenGLWidget

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 723 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alex111
    wrote on last edited by
    #1

    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();
    }
    +++++++++++++++++++

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved