title: How do I render a triangle in QOpenGLWidget?
body: <p>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.</p>
  
  <p>Here's what I have so far.</p>
  
  <p>Header:</p>
  
  <pre><code>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;
  };
  </code></pre>
  
  <p>Class:</p>
  
  <pre><code>Widget::Widget(QWidget *parent) :
      QOpenGLWidget(parent),
      ui(new Ui::Widget)
  {
      ui-&gt;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;
  }
  </code></pre>
  
  <p>Is there any example I could use to just render a basic triangle? I tried the one from here: <a href="https://www.khronos.org/assets/uploads/books/openglr_es_20_programming_guide_sample.pdf" rel="noreferrer">https://www.khronos.org/assets/uploads/books/openglr_es_20_programming_guide_sample.pdf</a>, but it threw a lot of errors that I couldn't work out.</p>
  
  <p>I also don't know how OpenGL contexts work in QOpenGLWidget.</p>
  
  <p>*EDIT: So it turns out that the examples were a separate package on my distro (Arch Linux). I was able to install them, and it looks like there is plenty there to get started.</p>
  
  <p>Thanks for your help!</p>