Sign in to follow this  
Madalina

ID3DXLine question

Recommended Posts

Madalina    100
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
Buckeye    10747
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);
D3DXCreateLine(m_pDevice,&lineSprite);
lineSprite->SetPattern(0xff00ff00);
lineSprite->SetPatternScale(2.0f);
lineSprite->Begin();
lineSprite->Draw(points,2,0xffff8080);
lineSprite->End();
lineSprite->Release();

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

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