texture on a heightmap

How can I put a texture on a heightmap?
It would be nice with some sample code…

Thanks

You kind of can’t. What you need to do is take your height map and create geometry from it. Once you create the geometry you can create tex coords and then you just draw it with a bound texture.

For example, say you have a 16x16 height map and you generate a vertex per pixel. You end up with 16 vertices in the x direction and 16 vertices in the z direction. Now you can assign tex coords to each vertex by,

for ( int x = 0; x < 16; x++ )
{
for ( int z = 0; z < 16; z++ )
{
Texcoord[z].u = x * ( 1.0f / 15.0f );
Texcoord[z].v = z * ( 1.0f / 15.0f );
}
}

Why? Because texcoord range from 0.0 to 1.0 and you want that range to extend over 16 vertices. The first vertex is 0.0 and the 16th vertex is 1.0 thats why you have 1/15 because the for loop only goes up to 15.

[This message has been edited by Kaycee (edited 12-04-2001).]