geometry shader line draw function:
// make thick line
// from : transformed point (by modelviewprojectionmatrix)
// to : trasformed point
// colorfrom : first point color
// colorto : second point color
void makeLine(in vec4 from, in vec4 to, in vec4 colorfrom, in vec4 colorto)
{
// triangle positions
vec4 position1 = from;
vec4 position2 = from;
vec4 position3 = to;
vec4 position4 = to;
// direction of line
vec2 line2d = position3.xy - position1.xy;
// normalized direction
vec2 direction = normalize(line2d);
// shift vector
vec2 vector;
// make vector perpendicular to line
vector.x = direction.y / screen.x;
vector.y = -direction.x / screen.y;
// normalizedwidthdiv2 : global variable width normalized from px width to normalized coords
// vec2 normalizedwidthdiv2 = width / screen;
// uniform vec2 screen; // screen size in px
// uniform vec2 width; // width of line in px
vec2 shift = normalizedwidthdiv2 * vector;
// shift positions
position1.xy -= shift;
position2.xy += shift;
position3.xy -= shift;
position4.xy += shift;
// emit triangles
gl_Position = position1;
gl_FrontColor = colorfrom;
EmitVertex();
gl_Position = position3;
gl_FrontColor = colorto;
EmitVertex();
gl_Position = position4;
gl_FrontColor = colorto;
EmitVertex();
EndPrimitive();
gl_Position = position1;
gl_FrontColor = colorfrom;
EmitVertex();
gl_Position = position2;
gl_FrontColor = colorfrom;
EmitVertex();
gl_Position = position4;
gl_FrontColor = colorto;
EmitVertex();
EndPrimitive();
}