Original Post
I am trying to make a line drawing function ie void DrawLine(float x1, float y1, float x2, float y2, D3DCOLOR color); i just cant seem to get it to work.... im sure the problem is in the DrawLine() function.. when i run it it runs with out failing it just does not draw the line... or even if some one wants to link me to a better line drawing function im fine with that.......... thanks for any help
#define HandleHRESULT(x,y) {HRESULT hr; hr =(x);if(FAILED(hr)){MessageBox(NULL,y,"DIRECTX ERROR", MB_OK);}}
#define VERTEX ( D3DFVF_XYZRHW | D3DFVF_DIFFUSE )
std::vector<Line*> g_lines;
struct Vertex2
{
float x, y, z, w;
DWORD color;
};
struct Line
{
float x1,y1;
float x2,y2;
Line(float fx1, float fy1, float fx2, float fy2)
{
x1 = fx1;
y1 = fy1;
x2 = fx2;
y2 = fy2;
};
};
std::vector<Line*> g_lines;
g_lines.push_back(new Line(20, 20, 175, 175));
/////// IN THE RENDER FUNCTION ///////
////////////////////////////////////////
//////
D3DCOLOR color = D3DCOLOR_XRGB(100, 50, 25);
for(int i = 0; i < g_lines.size(); i ++)
{
DrawLine(g_lines.at(i)->x1,g_lines.at(i)->y1,
g_lines.at(i)->x2,g_lines.at(i)->y2,
color);
}
//////////////////////////////
void DrawLine(float x1, float y1, float x2, float y2, D3DCOLOR color)
{
Vertex2 line[] =
{
{x1,y1,0,1,color},
{x1,y1,0,1,color},
};
LPDIRECT3DVERTEXBUFFER9 pLineList_vb = NULL;
HandleHRESULT(g_pd3dDevice->CreateVertexBuffer( 2*sizeof(Vertex2), 0, VERTEX,
D3DPOOL_DEFAULT, &pLineList_vb,
NULL ), "FAILED TO CREATE VERTEX BUFFER");
Vertex2 *pVertices2 = NULL;
HandleHRESULT(pLineList_vb->Lock( 0, sizeof(newline), (void**)&pVertices2, 0 ), "FAILED TO LOCK THE VERTEX BUFFER");
memcpy( pVertices2, newline, sizeof(newline) );
HandleHRESULT(pLineList_vb->Unlock(), "FAILED TO UNLOCK THE VERTEX BUFFER");
/// DRAW ///
HandleHRESULT(g_pd3dDevice->SetStreamSource( 0, pLineList_vb, 0, sizeof(Vertex2) ), "setStreamSource Failed");
HandleHRESULT(g_pd3dDevice->SetFVF( VERTEX ),"SETFVF FAILED");
HandleHRESULT(g_pd3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, 1),"Line List failed to draw");
pLineList_vb->Release();
}