OpenGL automatic texture coordinate generation

xiaoxiao2021-03-06  110

There are two ways in OpenGL to specify a texture coordinate: 1. Assign coordinates for each vertex by manual. Can be done by function GLTEXCORD * (). 2. Automatically assign coordinates for each vertex by OpenGL. This task is done by the function gltexgen * (). At first, my function is not very understanding of gltexgen * (), I don't know how OpenGL automatically generates texture coordinates. After receiving the relevant information, I started to understand: To complete the generation of automatic texture coordinates, first specify what kind of mode (what kind of algorithm) is to generate texture coordinates. In OpenGL1.1, you can specify three texture coordinate generation modes: GL_Object_Linear, GL_EYE_LINEAR, GL_SPHERE_MAP, in OpenGL1.3, add two generation modes: GL_REFLECTION_MAP, GL_NORMAL_MAP. The understanding of these modes is to use GLTEXGEN * () The key has also determined the effect after texture map. The specific meaning of these modes is analyzed below: 1.GL_Object_Linear In this mode, its texture generating function is a linear combination of vertex coordinates (X0, Y0, Z0, W0): generated coordinate = p0 * x0 p1 * Y0 P2 * Z0 P3 * W0; if we construct a plane as parameters (P0, P1, P2, P3): p0 * x p1 * y p2 * z p3 = 0; if (P0, P1, P2) has already Normalization, any point to this plane is: (p0 * x p1 * y p2 * z p3) / SQRT (p0 * p0 p1 * p1 p2 * p2) = p0 * x P1 * Y P2 * Z P3; It can be seen that the coordinate generated in this mode is equivalent to the distance of the vertex coordinates to a particular plane. 2.GL_EYE_LINEAR In this mode, its texture generation function is also a linear combination of the human eye coordinates (Xe, Ye, Ze, We) of the vertex: generated coordinate = p0 '* XE P1' * YE P2 '* ZE P3 '* WE; wherein: (P0', P1 ', P2', P3 ') = (P0, P1, P2, P3) * Inverse (m) It can be seen that GL_EYE_LINEAR and GL_OBJECT_LINEAR mode have similar texture generating functions, The only difference is that GL_Object_Linear is in the object space. When the performance changes, the texture coordinates will not change as the view, and GL_EYE_LINEAR is in the viewing space, and the texture coordinates will follow The change of the changes change, and the effect after the map is changed. 3.GL_sphere_map In this mode, the texture coordinate generating algorithm is as follows: Take U identifies a unit vector of the original point to the vertex under the viewing mark; identifies the method of the vertices in the viewing mark under the view mark; in r = trans ( RX, RY, RZ) Identifies the reflected vector of the vertex, then T can be calculated from the following formula: r = u-2 * TRANS (N') (N'U); another m = 2 * SQRT (Rx * RX RY * RY (RZ 1) * (RZ 1)), the generated coordinate: (S, T) = (Rx / m 0.5, RY / M 0.5); // In this case, specify R, Q coordinates are illegal. It can be seen that this mode is a reflection effect of the spherical surface on a plane.

转载请注明原文地址:https://www.9cbs.com/read-103242.html

New Post(0)