Forums > Jitter

using push and pop with jit.mgraphics

June 16, 2014 | 1:59 am

I love mgraphics, I hate mgraphics, I love mgraphics, I….
I must say, mgraphics, like its fellow bastard stepchildren Dict and SQL, is a super powerful addition to the max arsenal that is so poorly documented that trying to use it is a serious exercise in masochism. The mgraphics patch a day is a big help but it can be maddeningly difficult to use what I learn there with the altered syntax of jit.mgraphics.
Here is my current problem, I am hoping someone can help!
I want to draw something complicated that is the same every time through my loop, like the gradient in this example patch, then draw something else different each time over it, like some random black rectangles. So I understand from some JSUI examples, I issue a push_group command, write my gradient with all of its stops, then pop_group to save this as an image or surface that I can then recall quickly and efficiently at the beginning of every cycle by calling image_surface_draw. But I get errors using pop_group, which isn’t in the command list of the jit.mgraphics help, so I tried pop_group_to_source. I can’t "re-call" this image in the second step though.
Here is the patcher, the first example with no push and pop and the second with it. Can anyone tell me how to get the second to work?
Thanks, Bob

– Pasted Max Patch, click to expand. –

June 17, 2014 | 9:53 am

Unfortunately, push/pop is not currently exposed in jit.mgraphics, though it is in JS. What you would need to do instead is to use a named matrix as a "buffer" for a surface, then use image_surface_create/image_surface_draw to create the surface, then perform your changes. Maybe something like this:

– Pasted Max Patch, click to expand. –

Viewing 2 posts - 1 through 2 (of 2 total)