I have written a geo shader which gets a line (2 vertices) and should add width (length) along the line normal. Without the geo shader everything gets displayed correctly. I have also calculated the formula with pencil and paper (worked). I am calculating them with the formula:
N1 = (-(x2 - x1),y2-y1) N2 = (x2 - x1 , -(y2 - y1))
My code:
#version 330 core
layout(lines) in;
layout(triangle_strip, max_vertices = 4) out;
uniform float length;
void main()
{
//A -(x2 - x1) | y2 - y1
//B x2 - x1 | -(y2 - y1)
vec2 normal = normalize(vec2(gl_in[1].gl_Position.x - gl_in[0].gl_Position.x, gl_in[1].gl_Position.y - gl_in[0].gl_Position.y));
vec3 normalA = vec3(-normal.x, normal.y, 0);
vec3 normalB = vec3(normal.x, -normal.y, 0);
gl_Position = gl_in[0].gl_Position + (vec4(normalB, 0) * length);
EmitVertex();
gl_Position = gl_in[0].gl_Position + (vec4(normalA, 0) * length);
EmitVertex();
gl_Position = gl_in[1].gl_Position + (vec4(normalA, 0) * length);
EmitVertex();
gl_Position = gl_in[1].gl_Position + (vec4(normalB, 0) * length);
EmitVertex();
EndPrimitive();
}
P0 [0.3, 0.3] P1 [0.4, 0.3]