Web design - Page 452 OpenGL Super Bible! Figure 12-6 The

Page 452 OpenGL Super Bible! Figure 12-6 The terrain-drawing algorithm As you can see, this algorithm won t track the terrain exactly, but it is fast and simple to implement. It scans the terrain from left to right and from bottom to top, and starts a new GL_QUAD_STRIP primitive whenever the terrain type changes. Along the way it assigns lighting normals and texture coordinates for each point on the terrain. Automatically Generating Texture Coordinates Generating all those texture coordinates can be tedious. Fortunately, OpenGL has an answer that we can use! In the current drawing code, we issue glTexCoord2i calls glTexCoord2i(x * 2, y * 2); for each and every point in the terrain. But instead of doing this for each point, we can use the glTexGen functions to define the S and T coordinates in terms of the X and Z position in the scene (Y is used for the height). To generate coordinates for our terrain, then, we can use the following: static GLint s_vector[4] = { 2, 0, 0, 0 }; static GLint t_vector[4] = { 0, 0, 2, 0 }; glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeniv(GL_S, GL_OBJECT_PLANE, s_vector); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeniv(GL_T, GL_OBJECT_PLANE, t_vector); Here the GL_OBJECT_LINEAR mapping mode maps the texture coordinates from object coordinates: coordinate = X * vector[0] + Y * vector[1] + Z * vector[2] + W * vector[3] The vector array is specified with glTexGen function:
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Leave a Reply