0
\$\begingroup\$

I have a geometry shader that extrudes lines to rectangles in 2d (by outputting triangle strips). When the lines are not parallel to the X or Y axis, I'm getting parallelograms instead. Also, when the line is parallel to the X axis, it appears thinner.

Here's what my result looks like, drawing 4 lines at different angles: Here's what my result looks like, drawing 4 lines at different angles

Here's the geometry shader:

#version 150 core

layout(lines) in;
layout(triangle_strip, max_vertices = 4) out;
in vec3 Color[];
smooth out vec3 FColor;

void main() {
  vec3 g1 = gl_in[0].gl_Position.xyz;
  vec3 g2 = gl_in[1].gl_Position.xyz;
  vec3 v1 = normalize(g1 - g2) * 0.1;
  vec3 v2 = normalize(g2 - g1) * 0.1;

  FColor = Color[0];
  gl_Position = vec4(-v2.y + g1.x, v2.x + g1.y, 0.0, 1.0);
  EmitVertex();

  FColor = Color[0];
  gl_Position = vec4(v1.y + g2.x, -v1.x + g2.y, 0.0, 1.0);
  EmitVertex();

  FColor = Color[0];
  gl_Position = vec4(v2.y + g1.x, -v2.x + g1.y, 0.0, 1.0);
  EmitVertex();

  FColor = Color[0];
  gl_Position = vec4(-v1.y + g2.x, v1.x + g2.y, 0.0, 1.0);
  EmitVertex();

  EndPrimitive();
}

To test out the calculation, I ran the same set of vertices through the same calculation in GLM, took the results times 10.0 and plotted them using a web tool. Here's what I got: Here's what I got from the web plotter

So it looks to me like the basic calculation is correct. Can anyone help me understand what I'm doing wrong?

\$\endgroup\$
1
\$\begingroup\$

I am the world's biggest moron. My window is 800x600. That means that the X-axis from -1 to 1 is 800 pixels and the Y-axis from -1 to 1 is 600 pixels. If I use a square window, everything is... square.

\$\endgroup\$
  • \$\begingroup\$ Or you can scale things so that the Y-axis is -0.75 to 0.75 for example. \$\endgroup\$ – user253751 Jan 4 '17 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.