mattdesl / webgl-lines

some interactive content for a blog post
http://mattdesl.svbtle.com/drawing-lines-is-hard
MIT License
415 stars 37 forks source link

Help about the "expanded" version #3

Closed Yomguithereal closed 8 years ago

Yomguithereal commented 8 years ago

Hello @mattdesl. I wanted to thank you for your very insightful article and just wanted to ask you some questions. I am trying to apply your "expanded" version to optimize the drawing of a graph (I am currently using triangulated lines and this is causing me some performance issues unrelated with the GPU).

The thing I don't understand, and sorry if this is trivial and I missed it, is the following:

Let's say I want to draw a straight line. This line is composed of two points. With your methods I then need to render four vertices, no? How can the TRIANGLES drawing mode solves it since it is supposed to take every three consecutive vertices to produce triangles.

mattdesl commented 8 years ago

You need four vertices, one for each point in your line segment. However, you also need to submit the data with indices (aka elements) that tell the gpu how to draw the triangles. This way you can use 4 verts (imagine an indexed quad) rather than 6 verts, since two of the vertices can use the same element index. 😁

Yomguithereal commented 8 years ago

Oh. So it's the indices. Thanks a lot @mattdesl!