Sign in to follow this  
brucelee

How do I draw Lines in Direct3D

Recommended Posts

brucelee    122
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.

Share this post


Link to post
Share on other sites
rjackets    270
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.

Share this post


Link to post
Share on other sites
Agony    3452
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]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this