glTexGen problem

Started by
1 comment, last by GoogleJSJ 20 years, 9 months ago
Hi,all In the blue book,it said: " If the texture generation function is GL_OBJECT_LINEAR, the function g = p1 * xo + p2 * yo + p3 * zo + p4 * wo is used, where g is the value computed for the coordinate named in coord, p1, p2, p3, and p4 are the four values supplied in params, and xo, yo, zo, and wo are the object coordinates of the vertex. This function can be used to texture-map terrain using sea level as a reference plane (defined by p1, p2, p3, and p4). The altitude of a terrain vertex is computed by the GL_OBJECT_LINEAR coordinate generation function as its distance from sea level; that altitude is used to index the texture image to map white snow onto peaks and green grass onto foothills, for example. " But how to use it?I tried many times but failed. Thank you.
Advertisement
To use OBJECT_LINEAR, call :
GLfloat eq[4]={0,0,1.f,0}; /* set your equation here */
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_S, GL_OBJECT_PLANE, eq);
glEnable(GL_TEXTURE_GEN_S);

You may also do something equivalent with the T texture coordinate (if your texture is 2D).

Then you don''t need to call glTexCoord before glVertex. That''s the call of glVertex that will provoke texture coordinate computation.
To simplify

g = p1 * xo + p2 * yo + p3 * zo + p4 * wo

can also be writen as

g = p1 * xo + p2 * yo + p3 * zo + p4

becouse wo will always be 1 if you don''t specify it yourself (glVertex4f(...))

Another thing to note is that you may experience a (small) performance hit when using automatic texture generation. Depends on where your bottlenecks are.

You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.

This topic is closed to new replies.

Advertisement