GLUPICKMATRIX(3G)
π
GLUPICKMATRIX β okay so, gluPickMatrix(3G), bestie, let's TALK
the 3G manual page you didn't know you needed π
β¨ NAME β¨
gluPickMatrix β define a picking region π (yes literally just that, and honestly? iconic.)
πΈ C SPECIFICATION πΈ
void gluPickMatrix( GLdouble x,
GLdouble y,
GLdouble delX,
GLdouble delY,
GLint *viewport )
not me typing out every single parameter type exactly as given, because that's the vibe π
π¦ PARAMETERS π¦
x,yβ these two are the center of a picking region, measured in window coordinates. like, where's the lil circle you're drawing around your cursor? that's these. π―delX,delYβ the width and the height (respectively!! in that order!!) of the picking region, also in window coordinates. so likeβ¦ how big is the lil circle. πviewportβ the current viewport</c>, the one you'd get from aglGetIntegervcall. yes it's a pointer. yesGLint *. slay. π
π DESCRIPTION π
okay so here's the tea β β gluPickMatrix creates a projection matrix that you can use to restrict drawing to a small region of the viewport. why would you want that?? because bestie, that's how you figure out what objects are being drawn near the cursor π±οΈβ¨
the whole routine is:
- use
gluPickMatrixto restrict drawing to a tiny region around the cursor - enter selection mode (with
glRenderMode) - rerender the scene
and then π₯ β all primitives that would have been drawn near the cursor get identified and stored in the selection buffer. it's giving "who's near me right now" energy fr fr π₯
now, the matrix that gluPickMatrix creates gets multiplied by the current matrix, exactly like if you'd called glMultMatrix with the generated matrix. no cap. so to actually use it properly for picking:
- call
glLoadIdentityfirst, to load an identity matrix onto the perspective matrix stack - then call
gluPickMatrix - and finally call a command (like
gluPerspective) to multiply the perspective matrix by the pick matrix β¨
π¨ IMPORTANT CAVEAT, DO NOT SKIP THIS ONE: when you're usinggluPickMatrixto pick NURBS, be careful to turn off the NURBS propertyGLU_AUTO_LOAD_MATRIX. ifGLU_AUTO_LOAD_MATRIXis not turned off, then any NURBS surface rendered is subdivided differently with the pick matrix than the way it was subdivided without the pick matrix. π that's a real gotcha, that's not a vibe, that's a bug-adjacent situation, protect yourself. π«Ά
π EXAMPLE π
so when you're rendering a scene like this:
glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(...);
glMatrixMode(GL_MODELVIEW); /* Draw the scene */
a portion of the viewport can be selected as a pick region like this:
glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPickMatrix(x, y,
width, height, viewport); gluPerspective(...);
glMatrixMode(GL_MODELVIEW); /* Draw the scene */
see how it's the same but with the pick matrix sneaking in there?? that's the whole trick. chef's kiss π¨π³π i'm obsessed actually π
π SEE ALSO π
glGet(3G)glLoadIndentity(3G)glMultMatrix(3G)glRenderMode(3G)gluPerspective(3G)
(go read those too, they're all part of the squad π«Ά)
and that's the whole page, bestie!! π this was GLUPICKMATRIX(3G) β the 3G manual, GLUPICKMATRIX(3G) on the way out too, periodt. π
β¨ go forth and pick things. πΈπ¦π
π¦ 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