O'Reilly logo

3D Game Programming for Teens, Second Edition by Eric Grebler, Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Applying a Texture to a Terrain

More often than not, rather than coloring a terrain, you’ll probably want to apply a texture to it. You can apply a texture to a terrain just as you would any other entity. Before you continue, open the file called demo09-03.bb and make sure that the file grass1.jpg is in the same folder as the program. Add the following code to apply a grass texture to our terrain.

; Create the terrain
ground=CreateTerrain(512)
texture=LoadTexture ( "grass1.jpg" )
EntityTexture ground, texture

Go ahead and run the program now and you’ll see that your terrain now has the grass texture applied to it (see Figure 9.5).

Figure 9.5. A grassy texture has been applied to the terrain in demo09-03.bb.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required