capture to texture is so easy …

Jul 19, 2008 at 5:15pm

capture to texture is so easy …

… from one object to an other, as shown in the jit.gl.texture-copytotex.pat in max examples folder.

But what is the way to capture several GL objects to one texture?
[jit.gl.texture] can’t capture more than one.

I suppose [jit.gl.sketch] could be of any use, but I can’t find an example patch.
Could you tell me where can I find one, (forum? receipes?) or point out the technic.

Thank you very much.

#P window setfont “Sans Serif” 9.;
#P window linecount 5;
#P user com 380 416 264 196617 137;
#K set 0 42272 27749 8304 29289 28259 26992 25888 25701 8300 24864 25441 28788 30066 25888 25701 8308 25976 29813 29285 8306 36467 26980 25888 25697 28275 8300 25888 26209 26996 8305 29991 30062 8303 25194 25972 8283 27241 29742 26476 11892 25976 29813 29285 23840 29541 8310 28521 29728 29285 28016 27753 8292 10101 28261 8308 25976 29813 29285 8305 30057 8302 10085 29556 8304 24947 8309 28192 26217 25448 26981 29216 26989 24935 25888 28533 8310 26980 36463 11296 28001 26995 8309 28192 28514 27237 29728 13124 8308 25964 8305 30053 8295 29289 25715 26721 28773 11296 25972 8291 25888;
#K set 100 25966 8307 28814 25449 26217 24942 29728 34848 25445 8295 29289 25715 26721 28773 8256 25441 28788 30066 25888 28271 27999 25717 24426 26996 11879 27694 29797 30836 30066 25951 28573 24428 25951 29556 28515 27493 29184;
#K end;
#P window linecount 1;
#P user com 200 329 308 196617 34;
#K set 0 42272 16672 25445 29728 28514 27237 29728 25971 29728 24944 28780 26993 30094 8300 24864 29797 30836 30066 25888 8803 24944 8748 8292 25888 26209 36207 28192 29810 24932 26996 26991 28270 25964 27749;
#K end;
#P window linecount 2;
#P user com 193 165 398 196617 65;
#K set 0 42272 16672 25445 29728 28514 27237 29728 25971 29728 24944 28780 26993 30094 8300 24864 29797 30836 30066 25888 8820 25976 8717 42272 17253 29728 28514 27237 29728 11040 29537 8308 25976 29813 29285 8293 29556 8300 30057 8301 36973 25888 25441 28788 30066 36384 17473 20051 8300 10095 25194 25972 8283 27241 29742 26476 11892 25976 29813 29285 8256 28257 28005 8291 24944 23808;
#K end;
#P window linecount 1;
#N vpatcher 10 59 515 314;
#P window setfont “Sans Serif” 9.;
#P newex 60 143 43 196617 s grimy;
#P toggle 237 93 15 0;
#P message 237 116 94 196617 smooth_shading $1;
#P message 50 116 79 196617 color 0. 1. 0. 1.;
#P toggle 336 93 15 0;
#P message 336 116 90 196617 lighting_enable $1;
#P hidden newex 276 50 50 196617 loadbang;
#P toggle 149 93 15 0;
#P message 149 116 81 196617 depth_enable $1;
#P hidden message 277 72 14 196617 1;
#P fasten 4 0 9 0 341 138 65 138;
#P fasten 7 0 9 0 242 138 65 138;
#P fasten 6 0 9 0 55 140 65 140;
#P fasten 1 0 9 0 154 138 65 138;
#P hidden fasten 0 0 2 0 282 90 154 90;
#P connect 2 0 1 0;
#P hidden fasten 0 0 8 0 282 90 242 90;
#P connect 8 0 7 0;
#P hidden connect 3 0 0 0;
#P hidden fasten 0 0 5 0 282 90 341 90;
#P connect 5 0 4 0;
#P pop;
#P newobj 12 288 44 196617 p init @;
#P message 183 97 34 196617 reset;
#P newex 366 282 81 196617 prepend capture;
#P user ubumenu 366 256 72 196617 0 1 1 0;
#X add none;
#X add cap;
#X add tex;
#X add none;
#X add cap;
#X add tex;
#X prefix_set 0 0 0;
#X pattrmode 1;
#P newex 281 283 81 196617 prepend texture;
#P user ubumenu 281 257 72 196617 0 1 1 0;
#X add none;
#X add tex;
#X add cap;
#X add none;
#X add tex;
#X add cap;
#X prefix_set 0 0
0;
#X pattrmode 1;
#P newex 190 285 71 196617 prepend shape;
#P user ubumenu 190 259 72 196617 0 1 1 0;
#X add sphere;
#X add torus;
#X add cylinder;
#X add opencylinder;
#X add cube;
#X add opencube;
#X add plane;
#X add circle;
#X prefix_set 0 0
0;
#P newex 190 309 220 196617 jit.gl.gridshape foo @shape plane @texture cap;
#B color 5;
#P newex 343 76 81 196617 prepend capture;
#P user ubumenu 343 50 72 196617 0 1 1 0;
#X add none;
#X add cap;
#X add tex;
#X add none;
#X add cap;
#X add tex;
#X prefix_set 0 0
0;
#X pattrmode 1;
#P newex 256 74 81 196617 prepend texture;
#P user ubumenu 256 48 72 196617 0 1 1 0;
#X add none;
#X add tex;
#X add cap;
#X add none;
#X add tex;
#X add cap;
#X prefix_set 0 0
0;
#X pattrmode 1;
#P newex 89 487 200 196617 jit.gl.texture foo @name cap @mode static;
#B color 5;
#P message 82 372 28 196617 read;
#P message 113 372 31 196617 start;
#P toggle 19 351 15 0;
#P newex 19 372 55 196617 metro 20;
#P newex 19 404 103 196617 jit.qt.movie 256 256;
#P comment 35 353 149 196617 • read a movie and start metro.;
#P user jit.pwindow 18 449 66 66 0 1 0 0 1 0;
#P newex 89 463 200 196617 jit.gl.texture foo @name tex @mode static;
#B color 5;
#P newex 174 74 71 196617 prepend shape;
#P user ubumenu 174 48 72 196617 0 1 1 0;
#X add sphere;
#X add torus;
#X add cylinder;
#X add opencylinder;
#X add cube;
#X add opencube;
#X add plane;
#X add circle;
#X prefix_set 0 0
0;
#P newex 183 114 208 196617 jit.gl.handle foo @depth_enable 1 @radius 2.;
#P newex 13 264 145 196617 jit.window foo @depthbuffer 1;
#P window linecount 4;
#P user com 94 518 264 196617 81;
#K set 0 42272 12832 28514 27237 29811 8308 25972 30837 29285 29453 11884 25888 12645 29216 25971 29728 30062 8290 30054 26213 29216 28783 30066 8300 25888 26217 25448 26981 29216 27806 3374 27749 8242 36717 25888 25971 29728 30062 8290 30054 26213 29216 28783 30066 8291 24944 29813 29285 29216 16720 21061 21280 24944 28780 26979 24948 26991 28192 25717 8241 25970 8290 30054 26213 29216 29557 29216 30062 25888 26223 29293 25888 26510 28525 36468 29289 29045 25888 28528 25966 18252;
#K end;
#P window linecount 1;
#P newex 123 109 43 196617 r grimy;
#P newex 15 151 43 196617 jit.qball;
#P number 60 102 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 15 102 15 0;
#P newex 15 128 55 196617 metro 20;
#P newex 15 182 55 196617 t b erase b;
#P window linecount 2;
#P newex 174 134 300 196617 jit.gl.gridshape foo @shape opencube @texture tex @capture cap @color 0. 1. 0. 1.;
#B color 5;
#P window linecount 1;
#P newex 15 239 153 196617 jit.gl.render foo @camera 0 0 4;
#P fasten 31 1 32 0 402 277 371 277;
#P fasten 24 1 25 0 379 71 348 71;
#P fasten 29 1 30 0 317 278 286 278;
#P fasten 22 1 23 0 292 69 261 69;
#P connect 28 0 26 0;
#P fasten 32 0 26 0 371 305 195 305;
#P fasten 30 0 26 0 286 305 195 305;
#P fasten 27 1 28 0 226 280 195 280;
#P connect 33 0 10 0;
#P connect 12 0 1 0;
#P fasten 7 0 1 0 128 136 179 136;
#P connect 10 0 1 0;
#P fasten 23 0 1 0 261 93 179 93;
#P fasten 25 0 1 0 348 93 179 93;
#P fasten 11 1 12 0 210 69 179 69;
#P connect 16 0 14 0;
#P fasten 16 0 13 0 24 427 94 427;
#P connect 5 0 3 1;
#P fasten 17 0 16 0 24 398 24 398;
#P fasten 20 0 16 0 87 398 24 398;
#P fasten 19 0 16 0 118 398 24 398;
#P connect 18 0 17 0;
#P fasten 1 0 0 0 179 231 20 231;
#P fasten 2 1 0 0 42 210 20 210;
#P connect 2 0 0 0;
#P fasten 26 0 0 0 195 334 179 334 179 231 20 231;
#P connect 6 0 2 0;
#P connect 3 0 6 0;
#P connect 4 0 3 0;
#P window clipboard copycount 38;

#38945
Jul 19, 2008 at 6:04pm

#136324
Jul 19, 2008 at 6:56pm

Xtra! Thank you so much!

#136325
Nov 14, 2008 at 9:25pm

Is there a way to capture an entire scene to [jit.gl.texture]?

#136326
Nov 14, 2008 at 9:41pm

usetexture [texturename], to_texture < ---- send these messages to
jit.gl.render.

On Nov 14, 2008, at 4:25 PM, Derrick Giscloux wrote:

>
> Is there a way to capture an entire scene to [jit.gl.texture]?

#136327
Nov 14, 2008 at 11:08pm

> Is there a way to capture an entire scene to [jit.gl.texture]?

I mean: capture the render in a jit.gl.texture

I does not seem to work. Is it a least possible?

Thank you

#136328
Nov 14, 2008 at 11:21pm

no, this does work, as long as you have a jit.gl.texture object to
catch the texture. but you need to be careful about timing.
On Nov 14, 2008, at 6:08 PM, Derrick Giscloux wrote:

>
>> Is there a way to capture an entire scene to [jit.gl.texture]?
>
>
> I mean: capture the render in a jit.gl.texture
>
>
> I does not seem to work. Is it a least possible?
>
>
> Thank you

#136329
Nov 14, 2008 at 11:45pm

Oh yes! I can readback my context to matrix to texture then apply to a videoplane.
thank you.

#136330
Nov 15, 2008 at 9:47am

Ok, I am able to capture the context to a videoplane, thanks to readback technics (1.6.3 !!).

- Now I want some 3D elmts in the scene not to be captured in.
Can I tell some 3D objects (gridshape & else): “don’t be captured to the texture where I catch the render”?

It seems difficult since the readback reads back the entire scene?

#136331
Nov 15, 2008 at 2:03pm

I think I have to use a second context …

#136332
Nov 15, 2008 at 6:39pm

You should not need two contexts nor should you need to render to a matrix. What you need to do is

Prerequisites:

some objects to render
jit.gl.render/jit.window destination

an extra jit.gl.videoplane, and the jit.gl.texture @name capturetexture (or whatever name you want) to capture the scene to

Now you do:

erase to jit.gl.capture
render all the objects, with @automatic 0 and sending bangs in the proper order

2, send usetexture capturetexture, to_texture to jit.gl.render

this now populates the texture with the contents of the objects you banged (rendered).

Now you have to draw the texture. If you are rendering things with alpha, you should either use @blend_enable 0 on jit.gl.videoplane.

Now, send the texture to the videoplane, which should look something like:

jit.gl.videoplane mycontext @automatic 0 @blend_enable 0 @depth_enable 0

voila. No to matrix, no to second context, etc. Plenty of examples of this on the list.

#136333
Nov 16, 2008 at 4:39pm

Definitely avoid using shared_context for this, you’ll need it later
for the preview window:)

My new favorite way of capturing various objects to different textures
without thinking too much about the order, with automatic 1, proper
alpha channels, depth_enable, blending etc, etc, is using:

the jit.gl.sketch ™ (best gl object ever!)

the idea is to group objects using one sketch per group and drawobject
messages. Then capture those groups to texture simply using @capture
attribute to enclosing sketch.

another tip for good capturing is to avoid using erase message to
jit.gl.render, since it can fill the background around the captured
object with it’s alpha value, and it also can’t fill the background
with the alpha of 0.
So, i prefer using:

the jit.gl.sketch ™

for clearing the context, using: glclearcolor, glcleardepth, glclear
and @automatic 0

instead of sending erase to jit.gl.render, just bang this object at
the beginning of the draw cycle.

I’ve attached two patches to demonstrate this. First one demonstrates
what I mentioned above, and second one has a bit more details, ideas
and bugs.
Second example also shows how one could have a better blending and
depth sorting using old gl trick of first drawing all non-transparent
objects, and then transparent ones over them. This system queries
blend_enable and color attributes and then sorts drawing order based
on that.
It also has a post-process stage that uses slabs to process two
captured groups and then display this on the third videoplane.

I know this explanation is a bit short and fuzzy, so please feel free
to ask more questions!

-nesa

multicapture-simple:

– Pasted Max Patch, click to expand. –

*********************second example************************************

– Pasted Max Patch, click to expand. –
#136334
Nov 17, 2008 at 2:52pm

Thanks Vade below is the patch.
Sorry nesa, still not on Max V.

#P window setfont “Sans Serif” 9.;
#P flonum 309 415 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 309 434 84 196617 position $1 0. 0.;
#P window linecount 2;
#P newex 278 461 239 196617 jit.gl.videoplane asd @scale 0.5 @automatic 0 @blend_enable 0 @depth_enable 0 @texture mytex;
#P window linecount 5;
#P message 275 25 297 196617 ; max launchbrowser http://www.cycling74.com/forums/index.php?t=msg&th=34799&start=0&rid=3975&S=7ce5bd165531a69fd736c670d0f10f69;
#P flonum 501 208 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 501 230 69 196617 color 0. 1. 0.;
#P newex 278 137 284 196617 t b b b b b;
#P flonum 582 127 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 582 146 84 196617 position $1 0. 0.;
#P message 414 320 179 196617 usetexture mytex , to_texture , erase;
#P newex 56 404 144 196617 jit.window asd @pos 800 600;
#P newex 56 107 125 196617 t b b erase;
#P toggle 56 64 15 0;
#P newex 56 84 57 196617 qmetro 66;
#P newex 56 370 83 196617 jit.gl.render asd;
#P window linecount 2;
#P newex 482 252 247 196617 jit.gl.gridshape asd @automatic 0 @scale 0.2 @position -0.3 0. 0. @shape circle @color 1. 0. 0. 1.;
#P newex 550 168 211 196617 jit.gl.gridshape asd @shape torus @scale 0.2 @position 0.3 0. 0. @automatic 0;
#P window linecount 1;
#P newex 346 380 217 196617 jit.gl.texture asd @name mytex @automatic 0;
#P window linecount 2;
#P comment 597 320 235 196617 • to_texture = Copy the previously drawn frame to the named texture. Useful for feedback effects.;
#P connect 6 0 5 0;
#P connect 5 0 7 0;
#P connect 7 2 4 0;
#P connect 7 0 4 0;
#P fasten 9 0 4 0 419 353 61 353;
#P fasten 7 1 12 0 118 132 283 132;
#P connect 12 0 16 0;
#P fasten 17 0 16 0 314 455 283 455;
#P connect 18 0 17 0;
#P connect 12 1 1 0;
#P connect 12 2 9 0;
#P connect 12 3 3 0;
#P fasten 13 0 3 0 506 248 487 248;
#P connect 14 0 13 0;
#P connect 12 4 2 0;
#P fasten 10 0 2 0 587 164 555 164;
#P connect 11 0 10 0;
#P window clipboard copycount 19;

#136335
Dec 16, 2008 at 6:50am

Thanks for the tips – I found this thread helpful. I was not able to get @shared_context to work for my needs, but just throwing a @capture on my jit.gl object allowed me to easily use it as a texture for another object! Sweet!

Thanks,
James

#136336
Dec 16, 2008 at 7:30am

wish I had this thread like a year ago for my thesis! R

On Mon, Nov 17, 2008 at 9:52 AM, Derrick Giscloux
wrote:
>
> Thanks Vade below is the patch.
> Sorry nesa, still not on Max V.
>
>
> #P window setfont “Sans Serif” 9.;
> #P flonum 309 415 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window linecount 1;
> #P message 309 434 84 196617 position $1 0. 0.;
> #P window linecount 2;
> #P newex 278 461 239 196617 jit.gl.videoplane asd @scale 0.5 @automatic 0 @blend_enable 0 @depth_enable 0 @texture mytex;
> #P window linecount 5;
> #P message 275 25 297 196617 ; max launchbrowser http://www.cycling74.com/forums/index.php?t=msg&th=34799&start=0&rid=3975&S=7ce5bd165531a69fd736c670d0f10f69;
> #P flonum 501 208 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window linecount 1;
> #P message 501 230 69 196617 color 0. 1. 0.;
> #P newex 278 137 284 196617 t b b b b b;
> #P flonum 582 127 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P message 582 146 84 196617 position $1 0. 0.;
> #P message 414 320 179 196617 usetexture mytex , to_texture , erase;
> #P newex 56 404 144 196617 jit.window asd @pos 800 600;
> #P newex 56 107 125 196617 t b b erase;
> #P toggle 56 64 15 0;
> #P newex 56 84 57 196617 qmetro 66;
> #P newex 56 370 83 196617 jit.gl.render asd;
> #P window linecount 2;
> #P newex 482 252 247 196617 jit.gl.gridshape asd @automatic 0 @scale 0.2 @position -0.3 0. 0. @shape circle @color 1. 0. 0. 1.;
> #P newex 550 168 211 196617 jit.gl.gridshape asd @shape torus @scale 0.2 @position 0.3 0. 0. @automatic 0;
> #P window linecount 1;
> #P newex 346 380 217 196617 jit.gl.texture asd @name mytex @automatic 0;
> #P window linecount 2;
> #P comment 597 320 235 196617 • to_texture = Copy the previously drawn frame to the named texture. Useful for feedback effects.;
> #P connect 6 0 5 0;
> #P connect 5 0 7 0;
> #P connect 7 2 4 0;
> #P connect 7 0 4 0;
> #P fasten 9 0 4 0 419 353 61 353;
> #P fasten 7 1 12 0 118 132 283 132;
> #P connect 12 0 16 0;
> #P fasten 17 0 16 0 314 455 283 455;
> #P connect 18 0 17 0;
> #P connect 12 1 1 0;
> #P connect 12 2 9 0;
> #P connect 12 3 3 0;
> #P fasten 13 0 3 0 506 248 487 248;
> #P connect 14 0 13 0;
> #P connect 12 4 2 0;
> #P fasten 10 0 2 0 587 164 555 164;
> #P connect 11 0 10 0;
> #P window clipboard copycount 19;
>
>
>

#136337
Dec 16, 2008 at 9:34pm

jit.gl.sketch wuth drawobject commands is probably the easiest way to
capture a scene to texture. The other possible solution is to use
jit.gl.lua and something like:

jit.gl.begincapture(“mytex”, 0)
– draw scene here
jit.gl.endcapture(“mytex”, 0)

wes

#136338

You must be logged in to reply to this topic.