# Drawing lines with Sprites

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

## Recommended Posts

Heey my question is: Is it possible to draw simple lines with a color from X1, Y1 to X2, Y2. Draw a Rectangle whas easy but. I dont actuelly know if it is possible but I am sure you guys know. I also found out that when I use DrawPrimitiveUP and Sprites to draw and when I got the Sprite open ( I did call Begin but not jet End because I call End at the end of my frame ) the DrawPrimitiveUP lines arent drawed, why? Also when I use DrawPrimtiveUP I get and a line at the good position and a ugly lines at the top of my game: http://img36.imageshack.us/img36/7365/naamloospp.jpg This is how I set my vertex list: D3DTLVERTEX VertexList[2]; VertexList[0].X = X; VertexList[0].Y = Y; VertexList[0].Z = 0.0f; VertexList[0].RHW = 1.0f; VertexList[0].dColor = dColor; VertexList[1].X = X2; VertexList[1].Y = Y2; VertexList[1].Z = 0.0f; VertexList[1].RHW = 1.0f; VertexList[1].dColor = dColor; oDevice->DrawPrimitiveUP( D3DPT_LINELIST, 2, VertexList, sizeof( D3DTLVERTEX ) );

##### Share on other sites
You're getting two lines because the second argument for DrawPrimitiveUp is the number of primitives (i.e., lines), not the number of vertices.

You're telling the device to draw 2 lines.

##### Share on other sites
Quote:
 Original post by BuckeyeYou're getting two lines because the second argument for DrawPrimitiveUp is the number of primitives (i.e., lines), not the number of vertices.You're telling the device to draw 2 lines.

Yeah it looks perfect now, somebody got answer on the other questions?

##### Share on other sites
Sorry. Didn't go back to see your other questions.

With regard to "simple" lines, (in Dx9 ) there isn't a D3DXDrawLine(from-here, to there, with-color) function. DrawPrimitive(UP) is pretty much your choice for simple lines. For a more complicated version, you can use ID3DXLine (similar to a sprite).

You can use a sprite for drawing a horizontal or vertical line by selecting just a portion of the texture (1 or more pixels wide).
RECT srect;srect.left = 0;srect.right = 1;srect.top = 0;srect.bottom = 128;sprite->Draw(texture,&srect,NULL,&D3DXVECTOR3(top-end of line),some-color);

You can call sprite->Flush() to render what's accumulated before you make other rendering calls to the same area of the screen as the sprite. Then sprite->End() will render what's accumulated since the Flush().

##### Share on other sites
Quote:
 Original post by BuckeyeSorry. Didn't go back to see your other questions.With regard to "simple" lines, (in Dx9 ) there isn't a D3DXDrawLine(from-here, to there, with-color) function. DrawPrimitive(UP) is pretty much your choice for simple lines. For a more complicated version, you can use ID3DXLine (similar to a sprite).You can use a sprite for drawing a horizontal or vertical line by selecting just a portion of the texture (1 or more pixels wide).RECT srect;srect.left = 0;srect.right = 1;srect.top = 0;srect.bottom = 128;sprite->Draw(texture,&srect,NULL,&D3DXVECTOR3(top-end of line),some-color);You can call sprite->Flush() to render what's accumulated before you make other rendering calls to the same area of the screen as the sprite. Then sprite->End() will render what's accumulated since the Flush().

Much people say DrawPrimitive( UP because it is easy ) is better with performance then ID3DXLine.

##### Share on other sites
Quote:
 Much people say DrawPrimitive( UP because it is easy ) is better with performance then ID3DXLine.

Absolutely. Just wanted to let you know there are alternatives. If performance speed is a consideration, you may want to choose one method over another.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
18

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009805
• ### Who's Online (See full list)

There are no registered users currently online

×