gleTextureMode(3GLE)
π gleTextureMode β the GLE manual, bestie edition π
okay so this is gleTextureMode from section 3GLE of the GLE manual, and it's literally the function that decides how your textures wrap themselves around an extrusion. sit with me, we're gonna get through this together π«Ά
β¨ NAME β¨
gleTextureMode β set the type of GLE automatic texture coordinate generation. yes that's the whole job. it picks the vibe of your texture coords. π
πΈ SYNTAX πΈ
void gleTextureMode (int mode);
π ARGUMENTS π
modeβ a bitwise OR of GLE texture mode flags. that's it, that's the whole argument. one int carrying all your hopes and dreams. β¨
π¦ DESCRIPTION π¦
okay so, on top of the default glTexGen modes that OpenGL already hands you, the tubing library has its own little collection of automatic texture coordinate generation routines. and as if that wasn't enough, user-defined texture coord generation routines can be supplied too. main character library behaviour, honestly.
so like, to use texture mapping with the extrusion library, you have to remember to "do the obvious":
- Enable texture mapping through OpenGL
- Define and load (
glTexImage2D/glBindTexture) a texture - If using the routine below, then disable
glTexgGen
yes bestie, that last one is a real trap, don't skip it.
gleTextureMode is what you call to set the type of automatic texture coordinate generation to be used. the argument should be a bitwise-OR of any of these flags:
GLE_TEXTURE_ENABLEβ if this bit is set, then texturing is enabled. if this bit is NOT set, then automatic texture coordinate generation is disabled. so like, it's the on/off switch, but make it a bit. π
π« the "pick exactly one" section π«
the way in which the automatic texture coordinate generation actually happens is determined by one of the following flags. one and only one of these should be selected at a time. these tokens are enumerants, not bit-flags β do NOT get cute and OR them together, I'm begging. π
GLE_TEXTURE_VERTEX_FLATβ uses the vertexes "x" coordinate as the texture "u" coordinate, and the accumulated segment length as the "v" coordinate.GLE_TEXTURE_NORMAL_FLATβ uses the normal vector's "x" coordinate as the texture "u" coordinate, and the accumulated segment length as the "v" coordinate.GLE_TEXTURE_VERTEX_CYLβ usesu = phi/(2*pi) = arctan (vy/vx)/(2*pi)as the texture "u" coordinate, and the accumulated segment length as the "v" coordinate. in the above equation, "vx" and "vy" stand for the vertex's x and y coordinates.GLE_TEXTURE_NORMAL_CYLβ usesu = phi/(2*pi) = arctan (ny/nx)/(2*pi)as the texture "u" coordinate, and the accumulated segment length as the "v" coordinate. in the above equation, "nx" and "ny" stand for the normal's x and y coordinates.GLE_TEXTURE_VERTEX_SPHβ usesu = phi/(2*pi) = arctan (vy/vx)/(2*pi)as the texture "u" coordinate, andv = theta/pi = (1.0 - arccos(vz))/pias the texture "v" coordinate. in the above equation, "vx","vy" and "vz" stand for the vertex's x, y and z coordinates.GLE_TEXTURE_NORMAL_SPHβ usesu = phi/(2*pi) = arctan (ny/nx)/(2*pi)as the texture "u" coordinate, andv = theta/pi = (1.0 - arccos(nz))/pias the texture "v" coordinate. in the above equation, "nx","ny" and "nz" stand for the normal's x, y and z coordinates.GLE_TEXTURE_VERTEX_MODEL_FLATGLE_TEXTURE_NORMAL_MODEL_FLATGLE_TEXTURE_VERTEX_MODEL_CYLGLE_TEXTURE_NORMAL_MODEL_CYLGLE_TEXTURE_VERTEX_MODEL_SPHGLE_TEXTURE_NORMAL_MODEL_SPH
these define texture mapping modes that are very similar to those described above, except that the untransformed vertices and/or normals are used. as a result, textures tends to stick to the extrusion according to the extrusions local surface coordinates rather than according to real-space coordinates. this will in general provide the correct style of texture mapping when affine transforms are being applied to the contour, since the coordinates used are those prior to the affine transform. π§
π OPERATION π
to best understand how to use the above functions, it is best to understand how the tubing is actually drawn. let's start by defining some terms, bestie, because the vocabulary here is doing a lot.
the tubing library "extrudes" a "contour" along a "path". the contour is a 2D polyline. the path is a 3D polyline. we use the word "segment" to refer to a straight-line segment of the path polyline. we also interchangeably use the word "segment" to stand for the section of the extrusion that lies along a path segment. two meanings, one word, iykyk. π
the tubing library draws segments one at a time. it uses glPushmatrix() and glPopmatrix() to orient each segment along the negative z-axis. the segment starts at z=0 and ends at some negative z-value (equal to the length of the segment). the segment is then drawn by calling glVertex3f() (and glNormal3F()) by drawing the 2D contour at z=0 and again at z=-len. (of course, if the join style is one of the fancy ones, then the end-points are trimmed in a variety of ways, and do not land exactly on z=0, or z=-len, but they do come close). note that glBegin() and glEnd() are called around each segment. (note also that additional glBegins/Ends may be called to draw end-caps or filleting triangles for the more complex join styles.) β¨
the obvious way to automatically generate textures is to warp the glVertex() and glNormal() functions, and compute texture coordinates based on the 3-space vertex and normal coordinates. this is essentially what the tubing code does, except that it passes some extra parameters. the glBegin calls are wrapped, and the integer segment number and the floating-point length of the segment are passed in. by knowing the segment number, and the segment length, the texture coordinates can be adjusted. knowing the length allows the length to be accumulated, so that a texture is applied lengthwise along the extrusion. it is this accumulated length that is used in the FLAT and CYL mapping modes. π
for each vertex, not only are the vertex x,y,z coordinates available, but so is a contour vertex counter indicating which contour vertex this corresponds to. there is also a flag indicating whether the vertex corresponds to a front or back vertex (i.e. a z=0 or z=-len vertex). again, this info can be used to avoid confusion when drawing the more complex join styles.
π HINTS π
here are a few hints, tips, and techniques:
- Hint: Confused? RUN THE DEMOS! the best way to understand what all the different texture modes are doing is to see them in action. no cap, just go look. π₯
- Hint: the texture matrix can be used to your advantage! that is, you can use
glMatrixMode(GL_TEXTURE)to control how textures are mapped to the surface. in particular, you may/will want to use it to to rescale the V coordinate. - the origin of the contour will in general change the vertex x's and y's, thus changing the texture coordinates.
- the contour "up" vector will NOT influence the texture coordinates.
- for the FLAT and CYL modes, the accumulated length really is the accumulated length of the segments in modeling coordinates. unless the extrusion is very small, this length will probably be much larger than 1.0, and so the resulting texture coordinate will wrap. you will generally want to rescale the "V" coordinate to make the texture map fit. π
- if the texture is "swimming" around on the surface in an undesired way, try using the "MODEL" version of the texture generation flag.
- typically, you will NOT want to use the "SPH" versions of the texture generation engine unless you really, really have an extrusion for which spherical coordinates are appropriate. most uses of extrusions are best handled with the "FLAT" and "CYL" generation methods.
- user-defined texture generation callbacks are not currently implemented, but these should be very, very easy to hack in as desired. it should be easy to let your imagination run wild in here. look at
texgen.cβ what needs to be done should be obvious, I hope. when in doubt, experiment. π
π BUGS π
multiple threads using GLE share a single texture mode.
bestie. read that again. if you're threading, y'all are fighting over one global texture mode and there is no locking to save you. π
π SEE ALSO π
gleExtrusion, gleSetJoinStyle
β AUTHOR β
Linas Vepstas (linas@linas.org)
and that's the whole page, bestie!! this was GLE version 3.0, from the gleTextureMode(3GLE) page, and honestly she ate. πβ¨ go forth and texture responsibly. ππ¦
π¦ where this page comes from
- debian bookworm: libgle3-dev 3.1.0-10 Β· GPL-2.0-only
- debian trixie: libgle3-dev 3.1.2-1+b2 Β· GPL-2.0-only
- fedora 43: libgle-devel 3.1.0-36.fc43 Β· GPL-2.0-only OR (ClArtistic AND LicenseRef-Callaway-MIT)
- fedora 43: libgle-devel 3.1.0-36.fc43 Β· GPL-2.0-only OR (ClArtistic AND LicenseRef-Callaway-MIT)
- fedora 44: libgle-devel 3.1.0-37.fc44 Β· GPL-2.0-only OR (ClArtistic AND LicenseRef-Callaway-MIT)
- fedora 44: libgle-devel 3.1.0-37.fc44 Β· GPL-2.0-only OR (ClArtistic AND LicenseRef-Callaway-MIT)
- nixos 26.05: gle 3.1.2
- nixpkgs unstable: gle 3.1.2
- opensuse-leap 16.0: gle-devel 3.1.2-bp160.1.13 Β· GPL-2.0-or-later
- opensuse-leap 16.0: gle-devel 3.1.2-bp160.1.13 Β· GPL-2.0-or-later
- opensuse-leap 16.0: gle-devel 3.1.2-bp160.1.13 Β· GPL-2.0-or-later
- opensuse-leap 16.0: gle-devel 3.1.2-bp160.1.13 Β· GPL-2.0-or-later
- ubuntu jammy: libgle3-dev 3.1.0-10 Β· GPL-2.0-only
- ubuntu noble: libgle3-dev 3.1.2-1build1 Β· GPL-2.0-only
- ubuntu questing: libgle3-dev 3.1.2-1build1
- ubuntu resolute: libgle3-dev 3.1.2-1build2 Β· GPL-2.0-only
- ubuntu stonking: libgle3-dev 3.1.2-1build2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms