I am making a game like hill climb racing and wanted some advice regarding texture mapping an an uneven 2D terrain, I have mapped the texture on the terrain, but as i continue to play the game, after some time the ground texture starts to get distorted.
i did some debugging and found that:
//calculating texture co-ordinates
for(short i = 0; i < MAX_SEGMENTS; ++i)
{
CCPoint pt = hillBottomVertices[i];
hillBottomTexCoords[i].x = pt.x/terrainBottomTexSize;
hillBottomTexCoords[i].y = 1.0f - pt.y/terrainBottomTexSize;
log("point: X=%f Y=%f", hillBottomTexCoords[i].x, hillBottomTexCoords[i].y);
}
the texture coordinates values are like
point: X=0.937500 Y=0.594344
point: X=0.937500 Y=1.000000
point: X=1.093750 Y=0.565063
point: X=1.093750 Y=1.000000
point: X=2.031250 Y=0.347375
point: X=2.031250 Y=1.000000 ...so on
point: X=166.875000 Y=0.280531
point: X=166.875000 Y=1.000000 ... till
point: X=260.937500 Y=0.308594
point: X=260.937500 Y=1.000000 ...
... until the X co-ordinates goes beyond 256 which is also the size of the texture(size = 256) ..that the stretch starts to appear. As i move ahead the x co-ordinates keeps on increasing and the texture goes on stretching more.
how do i make sure that the texture co-ordinates in the x direction are close to 0...or maybe reach 256 (texture size = 256) and then reset, coz the tex coordinates in x direction depend on the vertices point in x direction and vertices in X goes on increasing.