Original Post
Hey. I am working on my terrain engine, and am getting some pretty wierd texture problems. The textures are loading correctly. Here is my rendering code:
Here is what it looks like when running
Here is what the sky texture looks like:
Here is what it looks like when running
Any ideas why this looks so bad? Maybe it looks correct and I have some sort of misunderstanding with how the rendering works. I was skimming through my directx9 book and noticed that the custom vertex they use has a float u and v value, used in conjunction with the D3DFVF_CUSTOMVERTEX I have, which are used to repeat a texture across a polygon. Is this what I have done wrong? Sorry, im a huge directx noob. If someone could point me in the right direction as to why this is looking so crappy, I would really appreciate it. Thanks.
pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
D3DXMatrixScaling(&matWorld, TERRAIN_X*15, TERRAIN_Y*15, TERRAIN_Y*15); //make the box scaled by the correct size, to fit the terrain
pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);
pd3dDevice->SetTexture(0, SkyTexture);
//set the source as the skybox vertex buffer for the index buffer
pd3dDevice->SetStreamSource(0, SkyBoxVB, 0, sizeof(CUSTOMVERTEX));
//set our index buffer to show what triangles to use.
pd3dDevice->SetIndices(SkyBoxIB);
//we draw triangles lists as blocks of 2 triangles at a time
pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,8,0,12); //we have 8 vertices, and 12 primitives
D3DXMatrixScaling(&matWorld, 1.0f, 1.0f, 1.0f); //we dont need to scale anymore, so set the world
//back to normal.
pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);
//apply the ground texture to the Index Buffer
pd3dDevice->SetTexture(0, GroundTexture);
pd3dDevice->SetStreamSource(0,TerrainVB,0,sizeof(CUSTOMVERTEX));
pd3dDevice->SetIndices(TerrainIB);
//draw the index buffer as triangle lists. (blocks of 2)
pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,TerrainVertices,0,TerrainPrimitives);
Here is my custom vertex:
// A structure for our custom vertex type
struct CUSTOMVERTEX
{
FLOAT fX, fY, fZ; // The untransformed, 3D position for the vertex
DWORD dwColor;
};
// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_TEX1)
Here is what the ground texture looks like:
Here is what it looks like when running
Here is what the sky texture looks like:
Here is what it looks like when running
Any ideas why this looks so bad? Maybe it looks correct and I have some sort of misunderstanding with how the rendering works. I was skimming through my directx9 book and noticed that the custom vertex they use has a float u and v value, used in conjunction with the D3DFVF_CUSTOMVERTEX I have, which are used to repeat a texture across a polygon. Is this what I have done wrong? Sorry, im a huge directx noob. If someone could point me in the right direction as to why this is looking so crappy, I would really appreciate it. Thanks.