How many jit.gl.texture objects

Emerson's icon

Hi! Supposing I have many spheres (jit.gl.gridshape) on the scene and I want to write index numbers on the surfaces of most of them. Is it necessary to dedicate a separate jit.gl.texture object for each numbered sphere or is there a workaround?

Rob Ramirez's icon

you can create a "textue atlas" with all the numbers and then use tex_map 1 and tex_plane_s/t to map them.

unfortunately the tex_plane_s/t use is archaic and not intuitive, but it works. you can even use it with jit.gl.multiple.

use this snippet to make things slightly more intuitive:

Max Patch
Copy patch and select New From Clipboard in Max.

Rob Ramirez's icon

here's a very old patch i made that uses the above technique with jit.gl.multiple to map key object output to locations in a font atlas using tex_plane_s/t.

in this case the math takes into account the characters in the font atlas are 16 x 16, but that's about the only hint i can give to how the jit.expr math works.

gl.multiple_texplane.maxpat
Max Patch

Emerson's icon

That's a fantastic patch, thank you.About jit.gl.multiple: I'm trying to include user interaction and make all shapes selectable by mouse to get the individual object "name"s from jit.gl.picker, so I think I cannot use jit.gl.multiple for that but I have to create shapes individually. I'm not experienced in Jitter so I have to ask with apologies: if this is adaptable to use without jit.gl.multiple (for the purpose I explained), can you give other hints in that direction?

Rob Ramirez's icon

IMO the best solution for mouse picking with gl.multiple is to use some jit.phys objects for this (phys.multiple phys.picker) in conjunction with the gl.multiple.

if desired, you can set @dynamics 0 on your jit.phys.world to so that you are only using the collisions functionality of the physics simulation.

search the file browser for phys.multiple.picking.maxpat for an example of using phys.picker with phys.multiple for mouse picking

Rob Ramirez's icon

here's a modified version of that example patch that removes dynamics and simplifies the setup a bit:

Max Patch
Copy patch and select New From Clipboard in Max.