Wide Lines without Geometry Shader

Im porting a GLES3 app to desktop (OSX OpenGL core 3.2). Since wide lines (glWidth >1) is now deprecated and one of my requirements are to keep the code portable between GLES3 and OpenGL3.2 I cannot use geometry shaders to draw lines that have a width > 1.0 so I write a code to convert theses 3d lines to triangle strip. It work fine however what I cannot figure out is how to write the vertex shader to insure that the triangles face the camera and that the line width is the appropriate number of pixels as the perspective kicks in… So the closer to the “line” (which is actually triangles) the bigger it gets… In GLSL how can I write a shader that keep a 3d perspective and insure that the triangles behave properly just like GL_LINES does?

Without a geometry shader, you essentially have to make the vertex shader work like a geometry shader. I.e. for each vertex, you need to pass in (at least) 2 attributes: the positions of the current vertex and the next vertex. These are the positions you would use for GL_LINES. After transforming both to screen space (NDC), you have the screen-space direction of the line so you can figure out the correct offset vector for the triangle vertex relative to the line vertex. The direction of the offset can be inferred from whether gl_VertexID is even or odd.

If you want to do line strips, you need to see 3 vertices at a time so that you can bisect the angle between the line segments to get reasonable joins.