Skip to main content
GameDev.net gamedev.net
🔒 Locked

Thick dashes lines

Started by jcurru May 25, 2013 at 6:55 PM 4 replies 1.5k views
Original Post
jcurru
jcurru

Hello!

I've benn googling for months but I finally surrender.
Maybe someone here can help me.
I'm writing a GIS (Geographic Information System). Therefore, I have to render complicated maps.

One of the main challenges consists in drawing thick dashed lines (roads, e.g).
Imagine a highway which is being constructed. It depends on the country, company, etc, but very often it's drawn as a discontinuous (dashed) thick line (yellow with red borders).

Ok.

Drawing a thick line is relatively easy using triangle strips.
Applying red/yellow/red color to borders is also easy: you can draw the line twice, or you can use one-dimensional textures.

But I can't figure out how can I achieve the discontinuity. If I use a bi-dimensional texture (half of it with alpha zero) then the problem is assigning texture coordinates. And that's a huge problem.

Ah! I cannot use shaders (I don't even know what a shader is ;-)

Any idea?
Please see attached an example.

Thanks in advance!!

Waterlimon
Waterlimon
Could you use a texture that wraps in the direction of the road, with half opaque half transparent?
o3o
deftware
deftware

I imagine you are simplifying things by drawing these lines as one continuous triangle-strip, in which case, if you use the actual points at the center of each joint, and use the distance between successive points, cumulatively, you can easily generate texture coordinates..

eg: current point position subtracted from next point's position, the length of that vector, scaled by how many dashes you want per unit of space, is the next coordinate along the opaque/transparent alternating axis of the texture, re-use that same coordinate when you begin to draw the next two triangles, and calculate the next coordinate by simply adding current-pos-subtracted-from-next-pos, scaled by an appropriate amount.

[ deftware.org ]
jcurru
jcurru

Could you use a texture that wraps in the direction of the road, with half opaque half transparent?

Thanks for your answer, Waterlimon. As I said in my post, "But I can't figure out how can I achieve the discontinuity. If I use a bi-dimensional texture (half of it with alpha zero) then the problem is assigning texture coordinates. And that's a huge problem".

jcurru
jcurru

I imagine you are simplifying things by drawing these lines as one continuous triangle-strip, in which case, if you use the actual points at the center of each joint, and use the distance between successive points, cumulatively, you can easily generate texture coordinates..

eg: current point position subtracted from next point's position, the length of that vector, scaled by how many dashes you want per unit of space, is the next coordinate along the opaque/transparent alternating axis of the texture, re-use that same coordinate when you begin to draw the next two triangles, and calculate the next coordinate by simply adding current-pos-subtracted-from-next-pos, scaled by an appropriate amount.

Yeah! Sounds great! So this is your proposal to solve what I called a "huge problem". It seems not so big now. So thank you very much!!

By the way: do you know where can I find the code to "trianglestrip" the line axis? I have my own function, but I don't like it.

Thanks again!

Waterlimon
Waterlimon
I think you can just mke the texture coordinates be the distance from the start of the road and it should work.
o3o

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.