Slight problem trying to map a texture over an array of vertices. My vertices shape a terrain but I cant get the texture to map over them.
My code: LPDIRECT3DVERTEXBUFFER9 p_dx_VertexBuffer;
OURCUSTOMVERTEX cv_Vertices[WIDTH * HEIGHT];
float flt_HeightData[WIDTH][HEIGHT];
if (FAILED(d3ddev->CreateVertexBuffer(WIDTH * HEIGHT * sizeof(OURCUSTOMVERTEX), 0, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, D3DPOOL_DEFAULT, &p_dx_VertexBuffer, NULL)))
{
MessageBox(hWnd, "Error while creating VertexBuffer", "FillVertices()", MB_OK);
}
VOID* p_Vertices;
if (FAILED(p_dx_VertexBuffer->Lock(0, WIDTH * HEIGHT * sizeof(OURCUSTOMVERTEX), (void**)&p_Vertices, 0)))
{
MessageBox(hWnd,"Error trying to lock", "FillVertices()", MB_OK);
}
else
{
memcpy(p_Vertices, cv_Vertices, WIDTH*HEIGHT*sizeof(OURCUSTOMVERTEX));
p_dx_VertexBuffer->Unlock();
}
That code is from the function that initialises my terrain. noise is my Perlin Noise class. struct OURCUSTOMVERTEX
{
float x,y,z;
DWORD color;
FLOAT U, V;
};
Is the vertex struct.
If the texture is not loading, be sure the texture file is within the folder or specified place, another thing is to change FVF declaration in the line if (FAILED(d3ddev->CreateVertexBuffer(WIDTH * HEIGHT * sizeof(OURCUSTOMVERTEX), 0, D3DFVF_XYZ|D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &p_dx_VertexBuffer, NULL))) from
D3DFVF_XYZ|D3DFVF_DIFFUSE to D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1
If the texture is not loading, be sure the texture file is within the folder or specified place, another thing is to change FVF declaration in the line if (FAILED(d3ddev->CreateVertexBuffer(WIDTH * HEIGHT * sizeof(OURCUSTOMVERTEX), 0, D3DFVF_XYZ|D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &p_dx_VertexBuffer, NULL))) from
D3DFVF_XYZ|D3DFVF_DIFFUSE to D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1
Yes, Im sure the texture is loading. I changed what you said but it didnt do anything.
Here is the code in my render function if it helps: // Render my terrain:
d3ddev->SetStreamSource(0, tVertexBuffer, 0, sizeof(OURCUSTOMVERTEX));
d3ddev->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
d3ddev->SetIndices(tIndexBuffer);
d3ddev->SetTexture(0, texture);
d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, WIDTH * HEIGHT, 0, (WIDTH - 1) * (HEIGHT - 1) * 2);