Jump to content
  • Advertisement
Sign in to follow this  

ID3DXLine question

This topic is 3056 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. I am trying to draw some dotted lines but it doesn't seem to work. The code is the following: ID3DXLine *line; ..... D3DXCreateLine( d3dDevice, &line ); line->SetWidth( 10 ); line->SetPattern( 0xffffffff ); ..... D3DXVECTOR2 points[2]; points[0] = D3DXVECTOR2( 0.0f, 50.0f ); points[1] = D3DXVECTOR2( 400.0f, 50.0f ); line->Draw( points, 2, 0xffffffff ); I found this in a example but for me it's not working. With this pattern it is only drawing one long line. If I try to use other pattern it doesn't draw anything. Can somebody explain to me if there are some settings they prevent my line to be drawn as dotted or maybe something else because I can't understand and the documentation on the internet is not helping me. Thank you in advance.

Share this post

Link to post
Share on other sites
First: ensure you have line->Begin() and ->End() around your draw call.

SetPattern sets the pattern of pixels to be drawn between each pair of points. The pattern you set is for 32 pixels in a row, all of the set color - i.e., a solid line.

To draw a dashed line, for example, try line->SetPattern(0xffff0000);

Remember, you may have to look closely to see the dashes as the pattern only covers 32 pixels!

You can make the dashes appear bigger by calling line->SetPatternScale(1.5f); or some larger scale factor.

LPD3DXLINE lineSprite;
D3DXVECTOR2 points[2];
points[0] = D3DXVECTOR2(50,50);
points[1] = D3DXVECTOR2(200,200);

This example code draws a dashed reddish line from (50,50) to (400,400), with noticeable dashes because they're scaled by a factor of 2.

NOTE: it appears you must set the pattern scale before you call ->Begin and can't change it between the Begin/End calls. To draw multiple lines with different scales, you have to use multiple Begin/End calls.

Share this post

Link to post
Share on other sites
Thank you very much. Even If I was using Begin() + End() I only got a straight line. Probably because of the scaling.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!