# Drawing lot's of trails

**URL:** https://discourse.libcinder.org/t/drawing-lots-of-trails/596
**Category:** Uncategorized
**Created:** [March 7, 2017, 12:14pm UTC](https://discourse.libcinder.org/t/drawing-lots-of-trails/596 "2017-03-07T12:14:48Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![hperigo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/hperigo/32/409_2.png) [@hperigo](https://discourse.libcinder.org/u/hperigo)
#### Post date: [March 7, 2017, 12:14pm UTC](https://discourse.libcinder.org/t/drawing-lots-of-trails/596/1 "2017-03-07T12:14:48Z")

</div>

Hi all,  
I’m currently doing a project that requires drawing a lot of trails, in my initial naive tests i tried to make a std::vector of VboMeshes but performance is not good. I can get about 100 trails, but it needs to be something like 6k.

The way I’m doing is similar to [this sample](https://github.com/paulhoux/Cinder-Samples/tree/v0.8.6/FastTrails) that Paul did, but there is probably a better way to do this with cinder-0.9.0+

The only info I found about this in the forum was this post, but I could not connect the dot’s 👀 on how to even start

> [@Transform feedback particle trails](http://discourse.libcinder.org/t/transform-feedback-particle-trails/521/):
>
> Hi, I’m thinking about adding trails for a transform feedback particle system. What would be the best way to do this? I could add some vertex attributes to store previous particle positions and generate the trail in a geometry shader. But since the number of attributes are limited, it would result in a quite short trail, I think. I’m ping-ponging 2 vbo’s in the transform feedback, so theoretically I could use more vbo’s to hold the positions, but I’m not sure how to connect them as a trail. Is …

anyway, any help is appreciated!  
thanks!

---

<div class="post-metadata">

### Author: ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)
#### Post date: [March 7, 2017, 12:29pm UTC](https://discourse.libcinder.org/t/drawing-lots-of-trails/596/2 "2017-03-07T12:29:04Z")

</div>

Let us know what you have trouble with. Can you move your particles with transform feedback without any trails?

---

<div class="post-metadata">

### Author: ![hperigo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/hperigo/32/409_2.png) [@hperigo](https://discourse.libcinder.org/u/hperigo)
#### Post date: [March 7, 2017, 1:03pm UTC](https://discourse.libcinder.org/t/drawing-lots-of-trails/596/3 "2017-03-07T13:03:19Z")

</div>

Hi gabor, thank you for the fast reply.

I forgot to post the test that I made:

> <https://gist.github.com/Hperigo/c70d1970a7244f8e367abdfc8d717425>

For now, I’m not moving the particles with transform feedback, Acctually, for test sake, it’s just the mouse pointer.

What I can’t get my head around is how to draw multiple trails in a single vboMesh ( I think is a lot more performant than drawing each trail as a VboMesh )

---

<div class="post-metadata">

### Author: ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)
#### Post date: [March 7, 2017, 3:00pm UTC](https://discourse.libcinder.org/t/drawing-lots-of-trails/596/4 "2017-03-07T15:00:33Z")

</div>

I did what was explained by Seph in the post above, but I was not using a `VboMesh`:

- one `Vbo` holds the particle positions
- and another `Vbo` holds the indices for the particles in the positions `Vbo` for each trail

---

<div class="post-metadata">

### Author: ![hperigo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/hperigo/32/409_2.png) [@hperigo](https://discourse.libcinder.org/u/hperigo)
#### Post date: [March 9, 2017, 12:21pm UTC](https://discourse.libcinder.org/t/drawing-lots-of-trails/596/5 "2017-03-09T12:21:59Z")

</div>

Hi there, sorry for de delay, I was trying to understand how to generate a VBO by “hand”. I’ve made some progress by constructing a mesh with the following structure:

For two particles with a trail of 4 points  
**Trail 1:**  
index0, index1, index1, index2, index2, index3

**Trail 2:**  
index4, index5, index6, index6, index6, index7

But for some reason the last point get’s connected to the first point of the next particle ( or vec2(0.f,0.f) , like the picture below shows

 ![](https://canada1.discourse-cdn.com/flex030/uploads/libcinder/original/1X/8fe6f7524436287f240e0506a4ea999fefbd5ad7.png)  
(drawing with immediate mode is fine)

I’ve updated the gist: [https://gist.github.com/Hperigo/c70d1970a7244f8e367abdfc8d717425](https://gist.github.com/Hperigo/c70d1970a7244f8e367abdfc8d717425)

I also did some tests trying to draw 60000 vertices and the performance was not good, so either I’m doing something wrong with the VBO or this is the wrong approach.

Some time ago I did manage to draw multiple lines using instancing, but I’m not sure how I would control each individual vertex position for each instance, maybe with a 32f Texture?

 ![](https://canada1.discourse-cdn.com/flex030/uploads/libcinder/original/1X/f6f8ff7330651172514d1d8ba9880abf413394a8.png)

---

<div class="post-metadata">

### Author: ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)
#### Post date: [March 9, 2017, 8:19pm UTC](https://discourse.libcinder.org/t/drawing-lots-of-trails/596/6 "2017-03-09T20:19:31Z")

</div>

Hi,

I don’t know if it helps, but I used to have a sample that is still available in the [dark history](https://github.com/paulhoux/Cinder-Samples/blob/6209b10c413cbdec061fab9176ba2eaaac2fa583/FastTrails/src/FastTrailsApp.cpp) of git. It uses a `deque` to easily add positions at the end of an array and remove them from the front. While probably not the _most_ efficient way to do things, it’s pretty fast anyway. From it, we update a `VboMesh` which uses a triangle strip as the primitive. To draw lines, you could simply make the trail very thin.

Remember that the number of vertices or primitives is not the only factor that determines performance. [Overdraw](https://developer.android.com/topic/performance/rendering/overdraw.html) can also affect performance greatly, especially on mobile platforms. I think your experiment with 60,000 vertices might be slow because of that.

-Paul

---

<div class="post-metadata">

### Author: ![hperigo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/hperigo/32/409_2.png) [@hperigo](https://discourse.libcinder.org/u/hperigo)
#### Post date: [March 9, 2017, 11:58pm UTC](https://discourse.libcinder.org/t/drawing-lots-of-trails/596/7 "2017-03-09T23:58:16Z")

</div>

Hi paul!  
thank you for the suggestions! I was actually following your sample and also [sansumbrella line renderer] ([https://github.com/sansumbrella/Pockets/blob/master/src/pockets/gl/LineRenderer.cpp](https://github.com/sansumbrella/Pockets/blob/master/src/pockets/gl/LineRenderer.cpp))

I tried again and managed to make the thing work, so thank you all =).

**But** , I’ve encontered another weird obstacle from the OpenGl world. It looks like when I resize the window or the fps is a little bit low I get a weird flicker in the VBO mesh, check it out:

https://player.vimeo.com/video/207720938

(The compression on the video is horrible, but you can get the point)  
any ideas?

The flicker only happens on the VboMesh btw

---

<div class="post-metadata">

### Author: ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)
#### Post date: [March 10, 2017, 12:30am UTC](https://discourse.libcinder.org/t/drawing-lots-of-trails/596/8 "2017-03-10T00:30:23Z")

</div>

My guess is that you have an error in they way you add positions. A single error in position offset or index might create a long chain of degenerate triangles, causing the ribbon to not render.

It could also be some kind of buffer overrun. Check the code that writes the new positions.

-Paul

---

<div class="post-metadata">

### Author: ![hperigo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/hperigo/32/409_2.png) [@hperigo](https://discourse.libcinder.org/u/hperigo)
#### Post date: [March 13, 2017, 5:31pm UTC](https://discourse.libcinder.org/t/drawing-lots-of-trails/596/9 "2017-03-13T17:31:42Z")

</div>

that was it!

thank’s Paul!

---

<div class="post-metadata">

### Author: ![Dan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/dan/32/886_2.png) [@Dan](https://discourse.libcinder.org/u/Dan)
#### Post date: [April 9, 2021, 8:30pm UTC](https://discourse.libcinder.org/t/drawing-lots-of-trails/596/10 "2021-04-09T20:30:04Z")

</div>

Hi all,  
I had to draw 3d lines with other 3D objects. I took the sample that Paul did and added the depth.  
I tested several methods in this [sample](https://github.com/brainswitchMedia/Cinder-Samples/tree/master/GPU3DLinesWithDepth)  
I tried to explain the methods in the sample. The C++ code is not optimized but the line-shader works fine.
