title: Draw GL_LINE in QOpenGLWidget using array of coordinates
body: <p>I have working application done using QtCreator. My render class is</p>
  <pre><code>GLRendWindow::GLRendWindow(QWidget *parent): QOpenGLWidget(parent)
  </code></pre>
  <p>Now I would like to draw objects using arrays with coordinates of vertices.<BR>
  I found some tutorial that draws triangle on this page:
  <a href="https://doc.qt.io/qt-5/qtgui-openglwindow-example.html" rel="nofollow noreferrer">OpenGL Window Example</a></p>
  <p>I tried to reused it to draw simple line</p>
  <pre><code>void GLRendWindow::drawLine()
  {
      GLfloat line[] =
      {
          0.5f, 1.0f,
          0.5f, -1.0f
      };
      GLfloat line_colors[] =
      {
          1.0f, 0.0f, 0.0f, // red
          0.0f, 0.0f, 1.0f, // blue
      };
      shaderProgram-&gt;bind();
      glVertexAttribPointer(posAttr, 2, GL_FLOAT, GL_FALSE, 0, line);
      glVertexAttribPointer(colAttr, 3, GL_FLOAT, GL_FALSE, 0, line_colors);
      glEnableVertexAttribArray(colAttr);
      glEnableVertexAttribArray(posAttr);
      glDrawArrays(GL_LINE, 0, 2);
      glDisableVertexAttribArray(posAttr);
      glDisableVertexAttribArray(colAttr);
      shaderProgram-&gt;release();
  }
  </code></pre>
  <p>Also my initialization method</p>
  <pre><code>void GLRendWindow::initializeGL()
  {
      initializeOpenGLFunctions();
      glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
      glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );
  
      shaderProgram = new QOpenGLShaderProgram(this);
      shaderProgram-&gt;addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
      shaderProgram-&gt;addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
      shaderProgram-&gt;link();
      posAttr = shaderProgram-&gt;attributeLocation(&quot;posAttr&quot;);
      colAttr = shaderProgram-&gt;attributeLocation(&quot;colAttr&quot;);
  }
  </code></pre>
  <p>and drawing method</p>
  <pre><code>void GLRendWindow::paintGL()
  {
      glClear( GL_COLOR_BUFFER_BIT );
      glMatrixMode( GL_MODELVIEW );
      glLoadIdentity();
      drawLine();
  
      if (isUpdated)
      {
         //some other stuff
  
          isUpdated = false;
      }
      glFlush();
  }
  </code></pre>
  <p>and resize method</p>
  <pre><code>void GLRendWindow::resizeGL(int w, int h)
  {
      glViewport( 0, 0, w, h );
      glMatrixMode( GL_PROJECTION );
      glLoadIdentity();
  
      if ( w &lt; h &amp;&amp; w &gt; 0 )
      {
          glFrustum( - 1.0, 1.0, - 1.0 * h / w, 1.0 * h / w, 1.0, 5.0 );
      }
      else
      {
          if ( w &gt;= h &amp;&amp; h &gt; 0 )
          {
              glFrustum( - 0.3 * w / h, 0.3 * w / h, - 0.3, 0.3, 0.5, 5.0 );
          }
      }
  }
  </code></pre>
  <p>But when I run app, nothing is drawed. No errors, no exceptions, nothing.
  In this tutorial I see</p>
  <pre><code>static const char *vertexShaderSource =
      &quot;attribute highp vec4 posAttr;\n&quot;
      &quot;attribute lowp vec4 colAttr;\n&quot;
      &quot;varying lowp vec4 col;\n&quot;
      &quot;uniform highp mat4 matrix;\n&quot;
      &quot;void main() {\n&quot;
      &quot;   col = colAttr;\n&quot;
      &quot;   gl_Position = matrix * posAttr;\n&quot;
      &quot;}\n&quot;;
  
  static const char *fragmentShaderSource =
      &quot;varying lowp vec4 col;\n&quot;
      &quot;void main() {\n&quot;
      &quot;   gl_FragColor = col;\n&quot;
      &quot;}\n&quot;;
  </code></pre>
  <p>and it is possible solution is hidden here, but I completely don't understand what for it is and what is going on here. I am even not sure if this is necessary for drawing simple line.<BR>
  What should I do to see stright line using array of coordinates?</p>