jit.gl.gridshape, jit.gl.render, rendering to a matrix and changing the dims

discopatrick's icon

I've got a problem in my patch: when I've got a jit.gl.gridshape and a jit.gl.render working together to draw a shape to a matrix, when I change the dimensions of that matrix, the resulting animation no longer fills the matrix.

I change my matrix dims all the time, and I need the gl side of things to adapt immediately. How should I do this?

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

Here's my example code. Click the message box labeled 'change dimensions...' to see what I mean.

Andro's icon
Max Patch
Copy patch and select New From Clipboard in Max.

here you go !

Anthony Palomba's icon

Hey DiscoPatrick,

Just out of curiosity why would you want to do this? If you want to make a smaller OpenGL display why not resize the pwindow? If you want to resize something for the purposes of displaying it, why are you not using a texture? Is there some other scenario where you would want to
resize a matrix?

Anthony

discopatrick's icon

Thanks Andro, that's great.

Anthony, I'd be happy to explain. My ultimate output is not to a screen or window, but to an array of DMX controllable lights. So eventually I have to convert my video from the GL paradigm (which doesn't care about pixels) to the matrix paradigm (which is of a fixed width and height) so that I can map each pixel value to the appropriate light.

Sometimes I spread the image across the whole array, sometimes just a section of it - so I need to be able to change the matrix dimensions.

discopatrick's icon

Andro - if I remove the jit.window from the patch, the animation stops. Seems odd. Is there a way to just use the matrix and pwindow?

SID's icon

Send the message 'visible 0' to the jit.window object.

Andro's icon

SID nailed it there ! I also do this when I'm sending video from max to syphon so I don't need to draw the render output twice.

discopatrick's icon

Hi Sid and Andro,

Yes, using '@visible 0' would indeed sort the problem. I guess I'm still a little confused as to why you need the window object at all. Seems unintuitive if you only wish to render to a matrix. Feels like a workaround rather than a proper solution.

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

Ahhh... I think I've found the answer. If I delete the window object, the jit.gl.node object stops outputting to its pwindow (and the matrix). But if I save, close, reopen, and then name the matrix the same as the other objects, it works:

Anthony Palomba's icon

Hey folks,

So I see how this is being done now, very cool. So I have a javascript interface that I have developed that creates objects and adds the to a rendering context. I want to take the output of this context and send it to a matrix as we did above. The problem is my objects are created in javascript land. I could create a jit.gl.node in javascript, but how do I tell it what objects I want it to capture?

Rob Ramirez's icon

you simply set the @drawto of your objects to the @name of the jit.gl.node.
the node can be inside or outside of the JS.

Anthony Palomba's icon

So my creating my gl.node would look something like this...

    RenderNode = new JitterObject("jit.gl.node", RendererContext);
    RenderNode.name = RenderNodeName;

And creating objects would look like this...
    var object = new JitterObject("jit.gl.gridshape", RendererContext);
    object.drawto = RenderNodeName;

Yes?

Rob Ramirez's icon

that would work, or you can skip the last line and do:var object = new JitterObject("jit.gl.gridshape", RenderNodeName);

Anthony Palomba's icon

So I am having a little bit of trouble with getting the output to show up in the output matrix. The problem seems to be the name I am trying to assign to the output matrix. When I try to have everything use the render context, javascript complains that the name is already in use. If I use a different render node name, and change the name of the matrix in javascript, I do not see the output.

I have attached my example. If you could give it a quick look over I would be grateful.

SceneRenderer.maxpat
Max Patch
SceneRenderer.js
js
Anthony Palomba's icon

I updated my example to better demonstrate the issue i am seeing. Also if I explicitly set the output matrix "name" in the patch to the render node name, I get the following error...

name GlRenderNode already in use. ob3d does not allow multiple bindings

Anthony Palomba's icon

Hey Rob, is there any word on this issue. It would be great to have this example working in javascript as well. The problem seems to be specifying the name of the output matrix within in the patcher or alternately trying to change it in script.

Rob Ramirez's icon

i'm not really sure what you're trying to achieve or what's not working.
your patch works fine for me.

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

if you want to capture your gl-scene output to a matrix, use gl.asyncread:

Anthony Palomba's icon

Hey Rob, thanks for your response. Yes using gl.asyncread works, but I thought the idea was to use jit.gl.node. In which case the example I posted should demonstrate that the matrix is not capturing the jit.gl.node output. I am not sure if this is a bug or not.

discopatrick's icon

Thanks Rob Ramirez, I think jit.gl.asyncread was exactly what I was looking for in the first place - it allows me to convert gl stuff back into the matrix world.

Rob Ramirez's icon

if jit.gl.node has capturing enabled (@capture 1) it will output a jit.gl.texture.
within javascript you can get that gl.texture by querying the jit.gl.node @out_name:var nodeoutname = mynode.out_name

you can then send this texture name to any jitter matrix, prepended with the "jit_gl_texture" message, and the matrix will draw the texture.
so from js, if you want to draw to a matrix in your patch, connect the js out to the matrix and send the message out:outlet(0, "jit_gl_texture", nodeoutname);