| Home | zeGraph lib | Lua lib | Custom lib | Tutorials | Notes | XML Script | C-Talk | Z-Script |
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19

Lesson 7 Texture

Applying texture to an object may seem complicated to those who has never touched the subject before. With zeTexture, you can easily paste your favorite image of arbitory size on any 3D surface. The zeTexture object will resize the image to the required size of OpenGL. Just image that you can draw wind field, ship route, contour lines, and so on on a map and then wrap the map on any 2D or 3D surface, you can have all kinds of map projections at your finger tips. Further more, you can render a scene directly to a zeTexture object and use it for texturing. Let's have a look at the result of this code:

require("register")

render, scene, node, light, texture, shape, xyz, nor, st
    = zeGrf.new("render" ,"scene", "node", "light",
      "texture", "polygon", "vertex", "vertex", "texcoord")

render:add(scene)
scene:set{node=node}
node:add(light, texture, shape)
shape:set{vertex = xyz, vertex_normal = nor, texture_coord = st,
          color = {1, 1, 1, 1}, type = "triangles"}

light:set{ambient = {0.4, 0.4, 0.4, 1}, position = {200, 0, 200}}

texture:set{image = "earth.png"}          -- use your own image here

arr = zeUtl.new("double")
zeMake.sphere2(arr, 150, 4)

xyz:add(arr)
arr:shift(3)
nor:add(arr)
arr:shift(3)
st:add(arr)

shape:rotatex(-60)

render:tofile("earth1.png")

shape:rotatex(60)

render:tofile("earth2.png")

earth1.png and earth2.png