I’m using shaders and the programmable pipeline, I need to connect two meshes with a line (maybe colored) but I just have the model matrices of these two objects. The line should start at the center of these objects so I assume the object-coords of the two points should be:
start point: 0,0,0
end point: 0,0,0
to connect the two objects I assume I’ll have to multiply these points in the shader by their respective object’s model matrix. And then multiply everything by the view matrix (this is common to the two objects). And eventually by the projection matrix.
I’ve always used shaders with vertex arrays, how would I pass two different vertices to a shader? Should I use uniforms for them too? And what function should I use to draw the line since both glDrawElements and glDrawArrays require a data array?
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.
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.
The line vertices would still have to be transformed by the view matrix.
Here’s an example:
GLuint vao, vbo;
If you need to add more point-pairs during runtime, update the std::vector, bind the VBO and call glBufferData.