Jump to content
  • Advertisement
Sign in to follow this  
brucelee

How do I draw Lines in Direct3D

This topic is 4879 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!