View Full Version : Heightmap tutorial texture mapping

05-01-2002, 04:24 PM
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?

05-02-2002, 01:48 PM
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)
glTexCoord2i(1, 0)
glTexCoord2i(1, 1)
glTexCoord2i(0, 1)

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.

for( int X = 0; X < Field_Height -LOD; X+=LOD )
for( int Z = 0; Z < 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);

Email me if you want a piece of my working code...
http://www.opengl.org/discussion_boards/ubb/smile.gif Bye bye