Jump to content
  • Advertisement


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


Drawing a polygon in Dx8 Problem!

This topic is 5792 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));



	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 = NULL;
Heres my fvf and vertex class
// 2d vertex


class C2DVert 
	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));

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));


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!