Archived

This topic is now archived and is closed to further replies.

UnknownPlayer

Drawing visible lines with D3D 8

Recommended Posts

How do I go about drawing visible 3D lines in D3D 8? I can set up an object in my game that''ll render line lists, but I don''t seem to get any output from it - what exact procedure do I need to use to draw just a straightline from one point in 3D space to another? ##UnknownPlayer##

Share this post


Link to post
Share on other sites

      void ssD3D::DrawLine(Vector start, Vector end, WSCOLOR clrStart, WSCOLOR clrEnd)
{
SPRITEVERTEX * pVertices = NULL;

pLineBuffer->Lock(0,2 * sizeof(SPRITEVERTEX),(BYTE**)&pVertices,0);

pVertices[0].color = D3DCOLOR_RGBA(clrStart.r,clrStart.g,clrStart.b,clrStart.a);
pVertices[1].color = D3DCOLOR_RGBA(clrEnd.r,clrEnd.g,clrEnd.b,clrEnd.a);

pVertices[0].x = start.x;
pVertices[0].y = start.y;
pVertices[1].x = end.x;
pVertices[1].y = end.y;

pLineBuffer->Unlock();

//pDevice->SetTransform(D3DTS_WORLD, NULL);


D3DXMATRIX Identity;
D3DXMatrixIdentity(&Identity);
pDevice->SetTransform(D3DTS_WORLD, &Identity);

pDevice->SetTexture(0,NULL);
pDevice->SetVertexShader(D3DFVF_SPRITEVERTEX);
pDevice->SetStreamSource(0, pLineBuffer, sizeof(SPRITEVERTEX));
pDevice->DrawPrimitive(D3DPT_LINELIST, 0, 1);
}

Ripped straight from source code to one of my games (2D side-scroller, so you'll have to add the extra dimension), but hope it helps you with the general procedure.

[EDIT:] SPRITEVERTEX is defined as:

  struct SPRITEVERTEX
{
float x, y, z;
DWORD color;
float u, v;
};


All this obviously assuming you've set up a D3D device and world/projection matrices etc.

[edited by - YodaTheCoda on March 5, 2003 2:51:33 AM]

Share this post


Link to post
Share on other sites
Ok I''ve got that, but now my screen is generating a seizure robot type effect that''s blocking out everything else on the screen? Did you suffer from this at some point, and if so what was the fix?

##UnknownPlayer##

Share this post


Link to post
Share on other sites