Archived

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

Drawing a polygon in Dx8 Problem!

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

OK ive spent the past few hours trying to work out the problem with my DrawPolygon function. Here it is:
  
void DrawPolygon(C2DVert *pVert,int NumVerts,IDirect3DDevice8*device)
{
	VOID* Vertices = NULL;
	IDirect3DVertexBuffer8 *pVB;

	//create the vertex buffer

	if(device->CreateVertexBuffer(NumVerts*sizeof(C2DVert), 0, FVF2D_PLAIN,
											D3DPOOL_DEFAULT, &pVB)!=D3D_OK)
	{
		MessageBox(NULL,"Error Creating Vertex Buffer","Error",MB_OK);
	}

	//lock and copy the square

	if(pVB->Lock(0, 0, (BYTE**)&Vertices, 0)!=D3D_OK)
	{
		MessageBox(NULL,"Error Locking","Error",MB_OK);
	}

	memcpy(Vertices, pVert, sizeof(pVert));

	//unlock

	pVB->Unlock();

	device->SetStreamSource(0, pVB, sizeof(C2DVert));

	if(device->DrawPrimitive(D3DPT_LINELIST , 0, NumVerts/2) != D3D_OK)
	{
		MessageBox(NULL,"Error Drawing Primative","Error",MB_OK);
	}

	pVB->Release();
	pVB = NULL;
}
  
Heres my fvf and vertex class
  
// 2d vertex

const DWORD FVF2D_PLAIN = (D3DFVF_XYZRHW | D3DFVF_DIFFUSE);

class C2DVert 
{
public:
	float m_x,m_y,m_z;
	float m_rhw;
	DWORD diffuse;

	void set(float x, float y, DWORD colour)
	{
		m_x = x;
		m_y = y;
		m_z = 0.5;
		m_rhw = 1.0;
		
		diffuse = colour;
	}
};
  
and heres how i call the function
  

	pPoly[0].set(20, 20,D3DCOLOR_ARGB(255,255,0,0));
	pPoly[1].set(100,20,D3DCOLOR_ARGB(255,255,255,0));
	pPoly[2].set(100,200,D3DCOLOR_ARGB(255,255,0,255));
	pPoly[3].set(300,400,D3DCOLOR_ARGB(255,0,255,0));
	
DrawPolygon(pPoly,4,pScreen->getDevice());

  
NOTE: I know i dont set the vertex shader here, because i do it somwhere else, and that isnt the problem as i have otherfunctions which render without vertex buffers and they work fine. Thanks for your help in advance. Ash

Share this post


Link to post
Share on other sites
It could be this line that is wrong:

memcpy(Vertices, pVert, sizeof(pVert));

sizeof(pVert) is *NOT* equal to the number of vertices you wish to copy. You will need something along the lines of:

memcpy(Vertices,pVert,numVerticesToCopy * sizeof(C2DVert));

Regards,
Sharky

Share this post


Link to post
Share on other sites