I am reading the book opengl game programming and i am playing with the code of chapter 8/10 (Textured heightfield terrain).
I have a question about texturing the terrain.
The code from the book uses one (grass) texture and put this texture on every quadrilateral. So in fact they use 1 texture and place let say 2000 times and the terrain is filled with green grass.
I downloaded some other terrain demo''s and they all used ONE texture to cover ALL of the terrain, not putting the texture on ONE quadrilateral. They some howe broke up the texture in pieces that fit on one quadrilateral.
I hope i make any sense
Can some explain to me how they can use one texture to cover all of the terrain or even better some code.
The flag demo in the same chapter shows how to apply a single texture to a grid like you want to do for the terrain. Remember, the terrain is just a grid with varying y-values for the height.
To spread the texture over a bunch of poly's, you need to calculate the texture coordinates for each vertex that is being texture mapped. When applying 1 texture per quad, the values range from 0.0 to 1.0, right? Well, when applying 1 texture to 10 quads, the texture coordinates for each quad will range from n/10 to (n+1)/10, where n is the index value for the current grid vertex.
Just take a look at the flag demo. It explains things better than I can at the moment.