Draw line segments

Hi there,

I have been developing an application in OpenGL 4.x for some time, I master notions of VBO, VAO, MVP matrices and hierarchical models. I’m now running into a problem for which I’m picturing two possible solutions but I’m not sure they’re the right ones

I have a structure that contains coordinates of lines (n x two points) that are recalculated periodically

I simply have to draw lines between these points as it was possible if I understood correctly with the glBegin(GL_LINES) of the old OpenGL

I thought of these two solutions :

  1. load the new coordinates into a VBO periodically in the render loop and draw lines. Is it good ? If so, what is the method to achieve this ?

  2. Create in a VBO a normalized segment aligned for example on the abscissa then apply successive transformations (scale, rotate, translate, etc.) to position the segment where it should be. Is it good ? If so, concerning the rotations I think I will have gimbal lock problems ? What do you think ?

  3. Other method ?

Many thanks in advance

Frank

I’d say you want option 1, as that lets you draw all lines with a single draw call. For option 2 you’d have to make separate draw calls (or use instanced draw calls) and also the amount of data that you have to transfer to the GPU to describe a full transformation for each line segment is more than the six floats you need to describe start and end point.

If you need to update the positions more frequently and profiling shows that it is a bottleneck you can look at the wiki page on Buffer Object Streaming for approaches to make the updates more efficient.

Ok thanks for your advices, meanwhile I found this interresting topic to read related to my question : Chapter 3. OpenGL's Moving Triangle

You don’t want to be using a transformation per line segment. If you have a set of lines which all move “in sync” (i.e. you’re translating or rotating the set as a whole), use a varying transformation. If the lines are moving independently, update their coordinates.

Ok thanks GClements for your response !