title: qt openGL - draw triangle
body: <p>So my goal is to (first) draw a triangle with openGL.</p>
  
  <p>my questions:</p>
  
  <p>1) How/when do both of my functions get called? I see that only one gets called. i.e. void MyGLWidget::paintGL. I am confused because as you can see I never call this function, it gets called automatically.I added a widget on my ui which I promoted to MyGLWidget. But when/why/how does it get (not) called?</p>
  
  <p>my code:
  myglwidget.cpp</p>
  
  <pre><code>#include "myglwidget.h"
  #include &lt;QtWidgets&gt;
  #include &lt;QtOpenGL&gt;
  #include &lt;GL/glu.h&gt;
  
  
  MyGLWidget::MyGLWidget(QWidget *parent)
      : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
  {
  }
  
  void MyGLWidget::initializeGL()
  {
      glClearColor(1,1,0,1);
      qDebug("init"); //&lt;-------never gets printed
  }
  
  void MyGLWidget::paintGL()
  {
      glClear(GL_COLOR_BUFFER_BIT);
      qDebug("painting"); //&lt;---- does get printed
      glColor3f(1,0,0);
      glBegin(GL_TRIANGLES);
          glVertex3f(-0.5,-0.5,0);
          glVertex3f(0.5,-0.5,0);
          glVertex3f(0.0,0.5,0);
      glEnd();
  }
  </code></pre>
  
  <p>myglwidget.h</p>
  
  <pre><code>#ifndef MYGLWIDGET_H
  #define MYGLWIDGET_H
  #include &lt;QGLWidget&gt;
  
  class MyGLWidget : public QGLWidget
  {
      Q_OBJECT
  public:
     explicit MyGLWidget(QWidget *parent = 0);
  
     void initializeGL();
     void paintGL();
     void resizeGL(int width, int height);
  private:
  
  };
  
  #endif // MYGLWIDGET_H
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      Widget w;
      w.setWindowTitle("OpenGL with Qt DAO");
      w.show();
  
      return a.exec();
  }
  </code></pre>