1gleTextureMode(3GLE)                  GLE                 gleTextureMode(3GLE)
2
3
4

NAME

6       gleTextureMode  - set the type of GLE automatic texture coordinate gen‐
7       eration.
8

SYNTAX

10       void gleTextureMode (int mode);
11

ARGUMENTS

13       mode      bitwise OR of GLE texture mode flags
14

DESCRIPTION

16       In addition to the default glTexGen modes that are supplied by  OpenGL,
17       the  tubing  library  also  contains  some of its own automatic texture
18       coordinate generation routines. In addition, user-defined texture coord
19       generation routines can be supplied.
20
21       To use texture mapping with the extrusion library, one must remember to
22       "do the obvious":
23
24              Enable texture mapping through OpenGL
25
26              Define and load (glTexImage2D/glBindTexture) a texture
27
28              If using the routine below, then disable glTexgGen
29
30       gleTextureMode can be used to set the type of automatic texture coordi‐
31       nate  generation to be used. The argument should be a bitwise-OR of any
32       of the following flags:
33
34       GLE_TEXTURE_ENABLE
35              If this bit is set, then texturing is enabled. If  this  bit  is
36              NOT  set,  then  automatic texture coordinate generation is dis‐
37              abled.
38
39       The way in which the automatic texture coordinate generation occurs  is
40       determined  by  one  of  the following flags. One and only one of these
41       should be selected at a time. These tokens  are  enumerants,  not  bit-
42       flags.
43
44       GLE_TEXTURE_VERTEX_FLAT
45              Uses  the vertexes "x" coordinate as the texture "u" coordinate,
46              and the accumulated segment length as the "v" coordinate.
47
48       GLE_TEXTURE_NORMAL_FLAT
49              Uses the normal vector's "x" coordinate as the texture "u" coor‐
50              dinate,  and  the  accumulated segment length as the "v" coordi‐
51              nate.
52
53       GLE_TEXTURE_VERTEX_CYL
54              Uses u = phi/(2*pi) = arctan (vy/vx)/(2*pi) as the  texture  "u"
55              coordinate,  and the accumulated segment length as the "v" coor‐
56              dinate.  In the above equation, "vx" and "vy" stand for the ver‐
57              tex's x and y coordinates.
58
59       GLE_TEXTURE_NORMAL_CYL
60              Uses  u  = phi/(2*pi) = arctan (ny/nx)/(2*pi) as the texture "u"
61              coordinate, and the accumulated segment length as the "v"  coor‐
62              dinate.  In the above equation, "nx" and "ny" stand for the nor‐
63              mal's x and y coordinates.
64
65       GLE_TEXTURE_VERTEX_SPH
66              Uses u = phi/(2*pi) = arctan (vy/vx)/(2*pi) as the  texture  "u"
67              coordinate, and v = theta/pi = (1.0 - arccos(vz))/pi as the tex‐
68              ture "v" coordinate. In the above equation, "vx","vy"  and  "vz"
69              stand for the vertex's x, y and z coordinates.
70
71       GLE_TEXTURE_NORMAL_SPH
72              Uses  u  = phi/(2*pi) = arctan (ny/nx)/(2*pi) as the texture "u"
73              coordinate, and v = theta/pi = (1.0 - arccos(nz))/pi as the tex‐
74              ture  "v"  coordinate. In the above equation, "nx","ny" and "nz"
75              stand for the normal's x, y and z coordinates.
76
77       GLE_TEXTURE_VERTEX_MODEL_FLAT
78
79       GLE_TEXTURE_NORMAL_MODEL_FLAT
80
81       GLE_TEXTURE_VERTEX_MODEL_CYL
82
83       GLE_TEXTURE_NORMAL_MODEL_CYL
84
85       GLE_TEXTURE_VERTEX_MODEL_SPH
86
87       GLE_TEXTURE_NORMAL_MODEL_SPH
88              These define texture mapping modes  that  are  very  similar  to
89              those  described  above,  except that the untransformed vertices
90              and/or normals are used. As a result, textures tends to stick to
91              the  extrusion according to the extrusions local surface coordi‐
92              nates rather than according to real-space coordinates. This will
93              in  general  provide  the  correct style of texture mapping when
94              affine transforms are being applied to the  contour,  since  the
95              coordinates used are those prior to the affine transform.
96

OPERATION

98       To best understand how to use the above functions, it is best to under‐
99       stand how the tubing is actually drawn. Let us start by  defining  some
100       terms.  The  tubing library "extrudes" a "contour" along a "path".  The
101       contour is a 2D polyline. The path is a 3D polyline. We  use  the  word
102       "segment"  to refer to a straight-line segment of the path polyline. We
103       also interchangeably use the word "segment" to stand for the section of
104       the extrusion that lies along a path segment.
105
106       The tubing library draws segments one at a time. It uses glPushmatrix()
107       and glPopmatrix() to orient each segment along the negative z-axis. The
108       segment  starts  at z=0 and ends at some negative z-value (equal to the
109       length of the segment). The segment is then  drawn  by  calling  glVer‐
110       tex3f()  (and  glNormal3F()) by drawing the 2D contour at z=0 and again
111       at z=-len. (Of course, if the join style is one of the fancy ones, then
112       the  end-points  are  trimmed  in  a  variety  of ways, and do not land
113       exactly on z=0, or z=-len, but they do come close). Note that glBegin()
114       and  glEnd() are called around each segment. (Note also that additional
115       glBegins/Ends may be called to draw end-caps or filleting triangles for
116       the more complex join styles.)
117
118       The  obvious  way  to  automatically  generate  textures is to warp the
119       glVertex() and glNormal() functions, and  compute  texture  coordinates
120       based on the 3-space vertex and normal coordinates. This is essentially
121       what the tubing code does, except that it passes some extra parameters.
122       The  glBegin  calls are wrapped, and the integer segment number and the
123       floating-point length of the segment are passed in. By knowing the seg‐
124       ment  number,  and  the  segment length, the texture coordinates can be
125       adjusted. Knowing the length allows the length to  be  accumulated,  so
126       that  a  texture  is applied lengthwise along the extrusion. It is this
127       accumulated length that is used in the FLAT and CYL mapping modes.
128
129       For each vertex, not only are the vertex x,y,z  coordinates  available,
130       but so is a contour vertex counter indicating which contour vertex this
131       corresponds to. There is also a flag indicating whether the vertex cor‐
132       responds  to  a  front  or  back  vertex (i.e. a z=0 or z=-len vertex).
133       Again, this info can be used to avoid confusion when drawing  the  more
134       complex join styles.
135

HINTS

137       Here are a few hints, tips, and techniques:
138
139       o      Hint:  Confused?  RUN THE DEMOS! The best way to understand what
140              all the different texture modes are doing  is  to  see  them  in
141              action.
142
143       o      Hint: The texture matrix can be used to your advantage! That is,
144              you can use glMatrixMode(GL_TEXTURE) to control how textures are
145              mapped  to  the surface. In particular, you may/will want to use
146              it to to rescale the V coordinate.
147
148       o      The origin of the contour will in general change the vertex  x's
149              and y's, thus changing the texture coordinates.
150
151       o      The  contour  "up" vector will NOT influence the texture coordi‐
152              nates.
153
154       o      For the FLAT and CYL modes, the accumulated length really is the
155              accumulated  length  of  the  segments  in modeling coordinates.
156              Unless the extrusion is very small, this length will probably be
157              much  larger  than  1.0, and so the resulting texture coordinate
158              will wrap. You will generally want to rescale the "V" coordinate
159              to make the texture map fit.
160
161       o      If  the  texture is "swimming" around on the surface in an unde‐
162              sired way, try using the "MODEL" version of the texture  genera‐
163              tion flag.
164
165       o      Typically,  you  will  NOT want to use the "SPH" versions of the
166              texture generation engine unless  you  really,  really  have  an
167              extrusion  for which spherical coordinates are appropriate. Most
168              uses of extrusions are best handled with the  "FLAT"  and  "CYL"
169              generation methods.
170
171       o      User-defined  texture  generation  callbacks  are  not currently
172              implemented, but these should be very, very easy to hack  in  as
173              desired.   It should be easy to let your imagination run wild in
174              here. Look at texgen.c -- what needs to be done should be  obvi‐
175              ous, I hope.  When in doubt, experiment.
176

BUGS

178       Multiple threads using GLE share a single texture mode.
179

SEE ALSO

181       gleExtrusion, gleSetJoinStyle
182

AUTHOR

184       Linas Vepstas (linas@linas.org)
185
186
187
188GLE                                   3.0                 gleTextureMode(3GLE)
Impressum