GLTEXGEN(3G)
π GLTEXGEN(3G) β bestie's guide to texture coordinate generation π
okay so welcome to glTexGen, aka the little fam of functions that control the generation of texture coordinates. yes there are SIX of them and yes they're all basically the same function wearing different outfits. come sit with me π«Ά
β¨ NAME β¨
glTexGend, glTexGenf, glTexGeni, glTexGendv, glTexGenfv, glTexGeniv β control the generation of texture coordinates. that's it. that's the whole vibe. π
π C SPECIFICATION π
the "scalar" girlies first (one value, no pointer, living simple):
void glTexGend( GLenum coord,
GLenum pname,
GLdouble param )
void glTexGenf( GLenum coord,
GLenum pname,
GLfloat param )
void glTexGeni( GLenum coord,
GLenum pname,
GLint param )
πΈ PARAMETERS πΈ
coordβ which texture coordinate we're talking about, bestie. has to be one ofGL_S,GL_T,GL_R, orGL_Q. no substitutions, this is not a build-your-own-coordinate situation.pnameβ the symbolic name of the texture-coordinate generation function. has to beGL_TEXTURE_GEN_MODE. like, must.paramβ a single-valued texture generation parameter, one ofGL_OBJECT_LINEAR,GL_EYE_LINEAR, orGL_SPHERE_MAP. pick one, queen.
π C SPECIFICATION (the vector edition) π
and now the pointer girlies, who brought their whole friend group (an array):
void glTexGendv( GLenum coord,
GLenum pname,
const GLdouble *params )
void glTexGenfv( GLenum coord,
GLenum pname,
const GLfloat *params )
void glTexGeniv( GLenum coord,
GLenum pname,
const GLint *params )
πΈ PARAMETERS πΈ
coordβ same as before, the texture coordinate, and it must be one ofGL_S,GL_T,GL_R, orGL_Q.pnameβ the symbolic name of the texture-coordinate generation function or the function parameters. this time it must beGL_TEXTURE_GEN_MODE,GL_OBJECT_PLANE, orGL_EYE_PLANE. yes, three options now, we're fancy.paramsβ a pointer to an array of texture generation parameters. ifpnameisGL_TEXTURE_GEN_MODE, the array has to hold a single symbolic constant β one ofGL_OBJECT_LINEAR,GL_EYE_LINEAR, orGL_SPHERE_MAP. otherwise,paramsholds the coefficients for the texture-coordinate generation function named bypname. iykyk. π
π DESCRIPTION π
glTexGen either picks a texture-coordinate generation function or hands over the coefficients for one of them. so basically it's the "choose your fighter" screen for texture coords.
coordnames one of the(s, t, r, q)texture coordinates, and it has to be one ofGL_S,GL_T,GL_R, orGL_Q.pnamehas to be one of three symbolic constants:GL_TEXTURE_GEN_MODE,GL_OBJECT_PLANE, orGL_EYE_PLANE.- if
pnameisGL_TEXTURE_GEN_MODE, thenparamspicks a mode:GL_OBJECT_LINEAR,GL_EYE_LINEAR, orGL_SPHERE_MAP. - if
pnameis eitherGL_OBJECT_PLANEorGL_EYE_PLANE, thenparamsholds the coefficients for the matching texture generation function.
π¦ the GL_OBJECT_LINEAR era π¦
if the texture generation function is GL_OBJECT_LINEAR, we use this function:
g=p1xo+p2yo+p3zo+p4wo
where g is the value computed for the coordinate named in coord, p1, p2, p3, and p4 are the four values you passed in params, and xo, yo, zo, and wo are the object coordinates of the vertex. β¨
and like, this is genuinely useful, not just theory β you can texture-map terrain using sea level as a reference plane (defined by p1, p2, p3, and p4). the altitude of a terrain vertex gets computed by the GL_OBJECT_LINEAR coordinate generation function as its distance from sea level; then that altitude indexes the texture image so you can slap white snow onto peaks and green grass onto foothills. it's giving mountain range ποΈ
ποΈ the GL_EYE_LINEAR era ποΈ
if the texture generation function is GL_EYE_LINEAR, we use this function:
g=p1xe+p2ye+p3ze+p4we
where
(p1p2p3p4)=(p1p2p3p4)Mβ1
and xe, ye, ze, and we are the eye coordinates of the vertex, p1, p2, p3, and p4 are the values supplied in params, and M is the modelview matrix when glTexGen is invoked.
β οΈ bestie listen β if M is poorly conditioned or singular, the texture coordinates generated by the resulting function may be inaccurate or undefined. no cap. that's a real "your texture is going to look cursed and nobody can help you" situation. π
note that the values in params define a reference plane in eye coordinates. and here's the sneaky part: the modelview matrix that gets applied to them may not be the same one in effect when the polygon vertices are transformed. this function establishes a field of texture coordinates that can produce dynamic contour lines on moving objects. main character energy, honestly. π
π the GL_SPHERE_MAP era π
if pname is GL_SPHERE_MAP and coord is either GL_S or GL_T, then the s and t texture coordinates are generated as follows:
let u be the unit vector pointing from the origin to the polygon vertex (in eye coordinates). let n sup prime be the current normal, after transformation to eye coordinates. let
f=(fxfyfz)T
be the reflection vector such that
f=uβ2nβ²nβ²Tu
finally, let m=2βfx+fy+(fz+1)2. then the values assigned to the s and t texture coordinates are
s=__+_
t=__+_
(okay yes that last one looks like the math got ate in the photocopier but that's literally what the page says, so i'm passing it to you exactly as it came. π« )
π«Ά turning it on and off π«Ά
to enable or disable a texture-coordinate generation function, call glEnable or glDisable with one of the symbolic texture-coordinate names β GL_TEXTURE_GEN_S, GL_TEXTURE_GEN_T, GL_TEXTURE_GEN_R, or GL_TEXTURE_GEN_Q β as the argument.
- when enabled, the specified texture coordinate is computed according to the generating function associated with that coordinate.
- when disabled, subsequent vertices just take the specified texture coordinate from the current set of texture coordinates. simple. comfy. π
and the defaults, because everyone wants to know the starting outfit:
- initially, all texture generation functions are set to
GL_EYE_LINEARand are disabled. - both
splane equations are(1, 0, 0, 0). - both
tplane equations are(0, 1, 0, 0). - all
randqplane equations are(0, 0, 0, 0).
π the multitexture note π
when the GL_ARB_multitexture extension is supported, glTexGen sets the texture generation parameters for the currently active texture unit, selected with glActiveTextureARB. so if your textures are acting mysterious, check which unit is actually active. π
π₯ ERRORS π₯
GL_INVALID_ENUMis generated whencoordorpnameis not an accepted defined value, or whenpnameisGL_TEXTURE_GEN_MODEandparamsis not an accepted defined value.GL_INVALID_ENUMis generated whenpnameisGL_TEXTURE_GEN_MODE,paramsisGL_SPHERE_MAP, andcoordis eitherGL_RorGL_Q.GL_INVALID_OPERATIONis generated ifglTexGenis executed between the execution ofglBeginand the corresponding execution ofglEnd.
π the last one is the classic trap. do NOT call this betweenglBeginandglEnd. the GL will simply say no and you will be sad.
β ASSOCIATED GETS β
like, if you wanna read back what you set:
glGetTexGenglIsEnabledwith argumentGL_TEXTURE_GEN_SglIsEnabledwith argumentGL_TEXTURE_GEN_TglIsEnabledwith argumentGL_TEXTURE_GEN_RglIsEnabledwith argumentGL_TEXTURE_GEN_Q
πΈ SEE ALSO πΈ
go read these next, they're all in the group chat:
glActiveTextureARB(3G), glCopyPixels(3G), glCopyTexImage2D(3G), glCopyTexSubImage1D(3G), glCopyTexSubImage2D(3G), glCopyTexSubImage3D(3G), glTexEnv(3G), glTexImage1D(3G), glTexImage2D(3G), glTexImage3D(3G), glTexParameter(3G), glTexSubImage1D(3G), glTexSubImage2D(3G), glTexSubImage3D(3G)
and that's the whole page, bestie π this was GLTEXGEN(3G) from the 3G manual, and that's the sign-off β go forth and generate some coordinates, you absolute icon. periodt. π
β¨π¦
π¦ where this page comes from
- centos-stream 9: gl-manpages 1.1-24.20190306.el9 Β· MIT and Open Publication
- fedora 43: gl-manpages 1.1-34.20190306.fc43 Β· Apache-2.0 AND HPND AND HPND-sell-variant AND MIT AND OpenPBS-2.3 AND SGI-B-2.0 AND W3C-19980720 AND X11
- fedora 44: gl-manpages 1.1-35.20190306.fc44 Β· Apache-2.0 AND HPND AND HPND-sell-variant AND MIT AND OpenPBS-2.3 AND SGI-B-2.0 AND W3C-19980720 AND X11
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms