title: Function to draw a line between two specified points for OpenGL 3.3
body: <p>I have been trying to figure out a way to create a function which draws a line between two points in OpenGL 3.3. I don't want to use <code>GL_LINES</code> as that is too ugly. I am using <a href="https://www.codeproject.com/Articles/199525/Drawing-nearly-perfect-2D-line-segments-in-OpenGL" rel="nofollow noreferrer">this library</a> but it is written for basic OpenGL, and is incompatible with 3.3, so I had to modify it a little.</p>
  <p>Currently, the line method works as provided in the library, with a slight modification in the end. After the method calculates all it needs for a nice line (the coordinates of the vertices and the colors), instead of placing vertices on screen with the glBegin stuff, it now stores them in an array. Then, I pass this array as buffer data to a VBO, and finally, I draw the vertices using glDrawArrays.</p>
  <p>To make this work, I have pointed out that the VBO is GL_DYNAIC_DRAW, and have preallocated the memory required for the array.</p>
  <p>In the line method I use this:</p>
  <pre><code>glBindVertexArray(vao);
  glBindBuffer(GL_ARRAY_BUFFER, vbo);
  glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
  </code></pre>
  <p>After this, I specify the vertex attributes and I draw the line.</p>
  <p>This works perfectly fine, but the problem is that it's significantly slower than the basic OpenGL version that the library uses. To test this, I created 2 programs (1 for basic and one for core OpenGL) which draw 10,000 lines in one render loop.</p>
  <p>I believe this is due to the constant changing of the buffer data with glBufferSubData. My question is how can I make this faster (or at least as fast as the basic OpenGL)? Just to specify, I need this as a generalized method like in the library, so specifying in the beginning how many lines and where they will be for the duration of the program will not be possible.</p>