1 Replies - 520 Views - Last Post: 24 February 2013 - 09:34 PM Rate Topic: -----

#1 Jigokuchi1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 24-February 13

adding tex coods to mesh, runtime error

Posted 24 February 2013 - 04:45 PM

im tryign to copy a mesh to add texture coodinates, but it crashes at runtime... what is wrong with this

class CPlane {
public:
	D3DMATERIAL9 material;
	LPD3DXMESH pMesh;
	LPD3DXMESH cMesh;
	LPDIRECT3DVERTEXBUFFER9 planeVertex;
	LPDIRECT3DINDEXBUFFER9 planeIndex;
	D3DXVECTOR3 pos;
	
	struct pVertex
	{
	D3DXVECTOR3 position;
	D3DXVECTOR3 normal;
	D3DXVECTOR2 uv;
	};

	pVertex planeVerts[4];
	WORD planeIndices[6];


	void Init(LPDIRECT3DDEVICE9	pd3dDevice)
	{
		D3DVERTEXELEMENT9 vertElem[] = 
		{
			{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
			{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
			{0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
		};

		ZeroMemory(&material, sizeof(D3DMATERIAL9));
		material.Ambient.r = 1.0;
		material.Ambient.g = 1.0;
		material.Ambient.b = 1.0;

		material.Diffuse.r = 1.0;
		material.Diffuse.g = 1.0;
		material.Diffuse.b = 1.0;
		
		D3DXCreatePolygon(pD3DDevice, 3, 4, &pMesh, 0);
		pMesh->CloneMesh(D3DXMESH_MANAGED, vertElem, pD3DDevice, &cMesh);

		pMesh = cMesh;
	
		
	

	//	pD3DDevice->CreateVertexBuffer(4*sizeof(Vertex), D3DUSAGE_WRITEONLY, 
	//	D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, D3DPOOL_MANAGED, &planeVertex, 0);

		pVertex* data;

		//planeVertex->Lock(0, 4*sizeof(Vertex),(void**) &data, 0);

		pMesh->LockVertexBuffer(0, (VOID**)&data);



		data[0].uv = D3DXVECTOR2(0.0f, 1.0f);
		data[1].uv = D3DXVECTOR2(0.0f, 0.0f);
		data[2].uv = D3DXVECTOR2(1.0f, 0.0f);
		data[3].uv = D3DXVECTOR2(1.0f, 1.0f);
		
	
		pMesh->UnlockVertexBuffer();

		memcpy(data, planeVerts, 4*sizeof(Vertex));

		planeVertex->Unlock();

		pD3DDevice->CreateIndexBuffer(6*sizeof(WORD),	D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX16, D3DPOOL_MANAGED, &planeIndex, 0);
		
		WORD* IndexData;

		planeIndex->Lock(0, 6*sizeof(WORD), (void**) &IndexData, 0);

		planeIndices[0] = 0; planeIndices[1] = 1; planeIndices[2] = 2;
		planeIndices[3] = 0; planeIndices[4] = 2; planeIndices[5] = 3;

		memcpy(IndexData, planeIndices, 6*sizeof(WORD));

		planeIndex->Unlock();

	}
	void Render(LPDIRECT3DDEVICE9 pD3DDevice)
	{
		pD3DDevice->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1);	

		//pD3DDevice->SetStreamSource(0, planeVertex, 0, sizeof(Vertex));
		//pD3DDevice->SetIndices(planeIndex);
		//pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);
		//pD3DDevice->SetMaterial(&material);

		pMesh->DrawSubset(0);
	}
}; 


Is This A Good Question/Topic? 0
  • +

Replies To: adding tex coods to mesh, runtime error

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: adding tex coods to mesh, runtime error

Posted 24 February 2013 - 09:34 PM

What is wrong is that your code assumes all operations were successful. Dumping your code here for what you're trying to do wont tell us anything because your error occurs during runtime and not compile time.

You need to review the relevant DirectX docs and place exception handling in your code to handle any specific errors your operations return.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1