Sign in to follow this  
SystemFiles

Drawing lines with Sprites

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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Buckeye
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.


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

Share this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Buckeye
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().


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

Share this post


Link to post
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.

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