TLDR version:

if I’m rendering from an ofVboMesh, using a vertex shader. Are the vertex index numbers in the shader (which I can get from `gl_VertexID`

) identical to their indexes within the mesh (or are they at least in the same order)?

Longer (may be useful to people trying to draw dotted lines).

I’m trying to draw dotted lines.

This is fairly easy for straight, single segment lines, I can use a cosine function in a fragment shader and change color based on distance from the start of the vertex. Like this: (adapted from here http://korkd.com/2012/02/15/dashed-lines/)

```
#version 150
in vec4 vertex_color;
in vec4 vertex_pos;
flat in vec4 vertex_start;
out vec4 Out_Color;
uniform int dotted;
void main()
{
if(dotted!=0){
if (cos(0.4*abs(distance(vertex_start.xy, vertex_pos.xy))) - 0.5 > 0.0) {
Out_Color = vec4(0,0,0,0);
return;
}
}
Out_Color = vertex_color;
}
```

But for multi-segment lines: e.g. a circle, this doesn’t work so well - the distance starts again at each new segment, so the on/off pattern begins again, rather than being consistent across the joins, and the dotted pattern is not consistent.

In this case, segment length is always consistent within a single mesh - I’m drawing circles, arcs or straight lines only) so my first thought is to pass length of segment as a uniform, and multiply that by the current vertex index number from `gl_VertexID`

to get a `running_distance`

and add that to the `distance`

used in the cosine function - as below.

```
#version 150
in vec4 vertex_color;
in vec4 vertex_pos;
flat in vec4 vertex_start;
out vec4 Out_Color;
uniform int dotted;
uniform float segmentLength;
void main()
{
float runningDist = segmentLength * gl_VertexID;
if(dotted!=0){
if (cos(0.4*abs(runningDist + distance(vertex_start.xy, vertex_pos.xy))) - 0.5 > 0.0) {
Out_Color = vec4(0,0,0,0);
return;
}
}
Out_Color = vertex_color;
}
```

I think should work quite nicely, assuming that the vertex index numbers in the shader are either identical to the vertex’s numbers within the mesh, or at least follow the same sequence. Obviously I could test this and see if it works for a few instances, but that might just show that it works on my machine, but turns out to be dependent on compiler, or environment, or whatever else.

So can I rely on this ordering?