# Heightmap tutorial texture mapping

Could someone help me texture the terrain generated in NeHe’s heightmap tutorial. I cannot however, seem to properly make it work. could someone please help me?

Well, I dont rmember how the code goes for that heighmap tutorial, but here is how you could get it working…

I am not sure if you use qauds or what not… But what you want to add is after you already done all of the magic to load the texture and made a mipmap or whatever.

glTexCoord2i(0, 0)
glVertex()
glTexCoord2i(1, 0)
glVertex()
glTexCoord2i(1, 1)
glVertex()
glTexCoord2i(0, 1)
glVertex()

Below is a piece of code I use for a simple terrain rendering with texture… LOD is simply the size of the polygons and roughness is a factor to make the terrain rougher or less rough. THe HeighField is the array created from reading the raw or whatever file you are using.

``````glBegin(GL_QUADS);
for( int X = 0; X &lt; Field_Height -LOD; X+=LOD )
{
for( int Z = 0; Z &lt; Field_Width -LOD; Z+=LOD )
{
glTexCoord2i( 0, 0 );
glVertex3i( X, (int)(HeightField[ X + (Field_Height*Z) ]*roughness), Z );

glTexCoord2i( 1, 0 );
glVertex3i( X, (int)(HeightField[ X + ((Z + LOD) * Field_Height) ]*roughness) , (Z + LOD));

glTexCoord2i( 1, 1 );
glVertex3i( X + LOD, (int)(HeightField[ (X + LOD) + ((Z + LOD)*Field_Height) ]*roughness), Z + LOD);

glTexCoord2i( 0, 1 );
glVertex3i( X + LOD, (int)(HeightField[ (X + LOD) + Z*Field_Height ]*roughness), Z);
}
}
glEnd();
``````

Email me if you want a piece of my working code… Bye bye