Archived

This topic is now archived and is closed to further replies.

Terrain question

This topic is 6024 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, 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. Thanks BoldyMan

Share this post


Link to post
Share on other sites
You should see the Demeter terrain engine at http://www.terrainengine.com/

Personnaly, I put only one texture on every quadrilateral but I use colors to change his aspect...

Share this post


Link to post
Share on other sites
How can you change the colors ? Do have some example code or
do you now a site ?

Share this post


Link to post
Share on other sites
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.


Kevin

Share this post


Link to post
Share on other sites
I change the color of each vertex with the glColor function (don''t forget to call glShadeModel(GL_SMOOTH) to have a nice interpolation).

Green vertexs looks like grass, white like snow...

Share this post


Link to post
Share on other sites