title: Get element ID in vertex shader in OpenGL
body: <p>I'm rendering a line that is composed of triangles in OpenGL.</p>
  
  <p>Right now I have it working where:</p>
  
  <p>Vertex buffer: <code>{v0, v1, v2, v3}</code></p>
  
  <p>Index buffer (triangle strip): <code>{0, 1, 2, 3}</code></p>
  
  <p><a href="https://i.stack.imgur.com/jvMMt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jvMMt.png" alt="enter image description here"></a></p>
  
  <p>The top image is the raw data passed into the vertex shader and the bottom is the vertex shader output after applying an offset to v1 and v3 (using a vertex attribute).</p>
  
  <p>My goal is to use one vertex per point on the line and generate the offset some other way. I was looking at gl_VertexID, but I want something more like an element ID. Here's my desired setup:</p>
  
  <p>Vertex buffer: <code>{v0, v2}</code></p>
  
  <p>Index buffer (triangle strip): <code>{0, 0, 1, 1}</code></p>
  
  <p>and use an imaginary <code>gl_ElementID % 2</code> to offset every other vertex.</p>
  
  <p>I'm trying to avoid using geometry shaders or additional vertex attributes. Is there any way of doing this? I'm open to completely different ideas.</p>