How do I draw Lines in Direct3D

Started by
1 comment, last by Agony 19 years, 2 months ago
Hello everyone. I have two questions for Direct3D experts. 1. How do I draw a dash or dot line or a dot line in Direct 3D ? 2. How do I draw a thick line and how do I control the thickness. I will very appreciate it if you can answer me.
Advertisement
Do you want the line to be 3d or just 2d on the screen? If you want it 3d then I think you will need to use a quad or sprite and scale to the length and width you need.
Dashed line:
Method A:
Use a bunch of vertices, and draw a D3DPT_LINELIST, so in reality, you'd have a bunch of short lines.
Method B:
Draw one single line, and have it textured with an Nx1 texture that is a dashed texture.

Dotted line:
Method A:
Use a bunch of vertices, and a draw a D3DPT_POINTLIST, much like method A for dashed lines.
Method B:
Again, like above, draw a single line, and texture it with an Nx1 texture that has dots, rather than dashes.

For the two Method Bs above, it might be beneficial to set the Sampler State D3DSAMP_ADDRESSU to D3DTADDRESS_WRAP, and set the texture x-coordinate on the second vertex to be larger than 1, depending on the length of the line, to get the right scale on the dots/dashes.

Thick line:
Draw a full-out quad that's really long and thin. You won't get rounded edges or anything (without few more triangles), but it'll give you a thick line. You can also use either method above to get a dotted or dashed effect, though Method B would probably be easier, and create far fewer triangles.

[edit]The textured dotted/dashed lines will require alpha-testing or alpha-blending, though. Shouldn't be an overly large deal, however, since they're typically rather thin.[/edit]
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke

This topic is closed to new replies.

Advertisement