GLUPICKMATRIX(3G)

πŸ“¦ version 1.1, in centos-stream 9, fedora 43, fedora 44

πŸ’… 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 a glGetIntegerv call. yes it's a pointer. yes GLint *. 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:

  1. use gluPickMatrix to restrict drawing to a tiny region around the cursor
  2. enter selection mode (with glRenderMode)
  3. 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:

  1. call glLoadIdentity first, to load an identity matrix onto the perspective matrix stack
  2. then call gluPickMatrix
  3. 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 using gluPickMatrix to pick NURBS, be careful to turn off the NURBS property GLU_AUTO_LOAD_MATRIX. if GLU_AUTO_LOAD_MATRIX is 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