Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The most straightforward method would be to create a VBO containing the worldspace points of all the lines you wish to draw with GL_LINES.</p> <p>The easiest is to use glDrawArrays. If you have extreme amounts of object pairs that need lines between (10.000s+) then it might make sense to store all the points in a VBO, and then use a IBO (index buffer) to say what points in the VBO are connected by a line.</p> <p>The line vertices would still have to be transformed by the view matrix.</p> <p>Here's an example: GLuint vao, vbo;</p> <pre><code>// generate and bind the vao glGenVertexArrays(1, &amp;vao); glBindVertexArray(vao); // generate and bind the buffer object glGenBuffers(1, &amp;vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); struct Point{ float x,y,z; Point(float x,float y,float z) : x(x), y(y), z(z) {} }; // create two points needed for a line. For more lines, just add another point-pair std::vector&lt;Point&gt; vertexData; vertexData.push_back( Point(-0.5, 0.f, 0.f) ); vertexData.push_back( Point(+0.5, 0.f, 0.f) ); // fill with data size_t numVerts = vertexData.size(); glBufferData(GL_ARRAY_BUFFER, sizeof(Point)*numVerts, &amp;vertexData[0], GL_STATIC_DRAW); // set up generic attrib pointers glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, numVerts*sizeof(Point), (char*)0 + 0*sizeof(GLfloat)); // "unbind" vao glBindVertexArray(0); // In your render-loop: glBindVertexArray(vao); glDrawArrays(GL_LINES, 0, numVerts); </code></pre> <p>If you need to add more point-pairs during runtime, update the std::vector, bind the VBO and call glBufferData.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload