I have set up this alphamap terrain that does multiple textures which works correctly except the textures seem off. The more you zoom out the more it the textures seem repeated. I believe this is because of the uv coordinates, looking for help on how to fix it as I am lost. Image of the problem: http://s13.postimg.org/dgh4awilj/image.png
float incrementSize, tu2Left, tu2Right, tv2Top, tv2Bottom;
int k = 0;
float texUIndex = 0;
float texVIndex = 0;
incrementSize = 1.0f / 255.0f;
tu2Left = 0.0f;
tu2Right = incrementSize;
tv2Bottom = 1.0f;
tv2Top = 1.0f - incrementSize;
for(DWORD i = 0; i < rows-1; i++)
{
for(DWORD j = 0; j < cols-1; j++)
{
indices[k] = i*cols+j;
vertices[i*cols+j].texCoord = D3DXVECTOR2(texUIndex , texVIndex + 1.0f);
vertices[i*cols+j].texCoord2 = D3DXVECTOR2(tu2Left, tv2Bottom);
indices[k+1] = i*cols+j+1;
vertices[i*cols+j+1].texCoord = D3DXVECTOR2(texUIndex + 1.0f, texVIndex + 1.0f);
vertices[i*cols+j+1].texCoord2 = D3DXVECTOR2(tu2Right, tv2Bottom);
indices[k+2] = (i+1)*cols+j;
vertices[(i+1)*cols+j].texCoord = D3DXVECTOR2(texUIndex + 0.0f, texVIndex + 0.0f);
vertices[(i+1)*cols+j].texCoord2 = D3DXVECTOR2( tu2Left, tv2Top);
indices[k+3] = (i+1)*cols+j;
vertices[(i+1)*cols+j].texCoord = D3DXVECTOR2(texUIndex + 0.0f, texVIndex + 0.0f);
vertices[(i+1)*cols+j].texCoord2 = D3DXVECTOR2(tu2Left, tv2Top);
indices[k+4] = i*cols+j+1;
vertices[i*cols+j+1].texCoord = D3DXVECTOR2(texUIndex + 1.0f, texVIndex + 1.0f);
vertices[i*cols+j+1].texCoord2 = D3DXVECTOR2(tu2Right, tv2Bottom);
indices[k+5] = (i+1)*cols+j+1;
vertices[(i+1)*cols+j+1].texCoord = D3DXVECTOR2(texUIndex + 1.0f, texVIndex + 0.0f);
vertices[(i+1)*cols+j+1].texCoord2 = D3DXVECTOR2(tu2Right,tv2Top);
k += 6; // next quad
texUIndex++;
tu2Left += incrementSize;
tu2Right += incrementSize;
}
texUIndex = 0;
texVIndex++;
tu2Left = 0.0f;
tu2Right = incrementSize;
// Increment the tv texture coords for the alpha map.
tv2Top -= incrementSize;
tv2Bottom -= incrementSize;
}