Skip to main content
GameDev.net gamedev.net
🔒 Locked

Terrain question

Started by boldyman Jul 20, 2001 at 10:11 AM 3 replies 1k views
Original Post
boldyman
boldyman
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
bobatefrei
bobatefrei
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...
khawk
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
Admin for GameDev.net.
bobatefrei
bobatefrei
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...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.