B
B
black_list_man2021-05-13 18:59:28
OpenGL
black_list_man, 2021-05-13 18:59:28

How to draw thick dashed lines in OpenGL?

I am using triangulation to draw thick lines. Each segment turns into a rectangle consisting of two triangles.
609d4b112c8a2938836966.png
Next, in order to add a dotted line, I create a texture from a single alpha channel that describes the pattern. To prevent the pattern from starting over on each segment, I calculate the lineSoFar parameter (the length of the line from the beginning), which essentially acts as a texture coordinate. In the fragment shader I use the value of the alpha channel to determine where the dash is and where the gap is.

float a  = texture2D(u_tex, v_normal/u_tex_len).a;
gl_FragColor = u_color*a;

But this only works if you do not calculate the miter during triangulation.
609d4c3852c67820002174.png
When you add a miter, the pattern stretches. Which is logical, because the length of the outer edge is different from the length of the inner one.
609d4bea1d5a8438429689.png
How to achieve such a result?609d4c889345a780776122.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question