Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Using QOpenGLWidget
Forum Updated to NodeBB v4.3 + New Features

Using QOpenGLWidget

Scheduled Pinned Locked Moved Game Development
qopenglwidgetopenglopengl es2.0widgets
2 Posts 2 Posters 1.8k Views 3 Watching
  • 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.
  • inefariusI Offline
    inefariusI Offline
    inefarius
    wrote on last edited by inefarius
    #1

    Hello,
    I'm trying to use OpenGL inside of Qt using QOpenGLWidget, but I am having a hard time finding any relevant examples. I am new to OpenGL, so I am trying to learn how to use it, but the tutorials that I find don't seem to apply particularly well in QOpenGLWidget. Right now, all I want to do is render a triangle to start with.

    Here's what I have so far.

    Header:

    namespace Ui {
    class Widget;
    }
    
    class Widget : public QOpenGLWidget, protected QOpenGLFunctions
    {
    public:
        explicit Widget(QWidget *parent = 0);
        ~Widget();
    
    protected:
        void initializeGL();
        void resizeGL(int, int);
        void paintGL();
    
    private:
        Ui::Widget *ui;
    };
    

    Class:

    Widget::Widget(QWidget *parent) :
        QOpenGLWidget(parent),
        ui(new Ui::Widget)
    {
        ui->setupUi(this);
    }
    
    void Widget::initializeGL()
    {
        // Set up the rendering context, load shaders and other resources, etc.:
        initializeOpenGLFunctions();
        glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
    }
    
    void Widget::resizeGL(int w, int h)
    {
        // Update projection matrix and other size-related settings:
    }
    
    void Widget::paintGL()
    {
        // Draw the scene:
        glClear(GL_COLOR_BUFFER_BIT);
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    

    Is there any example I could use to just render a basic triangle? I tried the one from here: https://www.khronos.org/assets/uploads/books/openglr_es_20_programming_guide_sample.pdf, but it threw a lot of errors that I couldn't work out.

    I also don't know how OpenGL contexts work in QOpenGLWidget.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      djvi
      wrote on last edited by
      #2

      http://www.trentreed.net/blog/qt5-opengl-part-0-creating-a-window/

      Follow thoose tutorials or at least the part 0, 1 ,2 ,3a, 3b and you will have decent basis to start.

      In the tutorial he use QOpenGLWindow which isn't really far from QOpenGLWidget so I think you should be able to adapt his code a bit to suit your need but if you didn't succed to do it ask here again.

      Do you look for opengl ressources to ?

      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