cutting shapes in GL

Mar 21, 2007 at 5:22pm

cutting shapes in GL

I’m trying to figure out a clever way to make a thick-lined rectangle in sketch, basically creating a frame that something can be viewed through, but I’m coming up blank.
In LCD, I can specify pen thickness, which is great – no such luck in gl.sketch.
My first thought is to use a blend mode and 2 sketch objects, with the “top” sketch object using 2 planes and blendmodes to knockout the middle of a plane, and show what’s underneath. This didn’t work.
My next thought was to use 2 gl.gridshapes with matrix output and use jit.op @op – to subtract a smaller plane from a larger one, however, the scale message doesn’t seem to affect the matrix output! And I’m not sure this would really work anyway…
I’m stumped. Any thoughts? Has anyone done this before? (BTW, I don’t count drawing 4 planes to create a perimeter as “clever” :) What I REALLY want to know is if it’s possible to snip up planes using other shapes!)

peter.

#30956
Mar 21, 2007 at 7:18pm

On 21-mrt-2007, at 18:22, pnyboer wrote:

>
> I’m trying to figure out a clever way to make a thick-lined
> rectangle in sketch, basically creating a frame that something can
> be viewed through, but I’m coming up blank.
> In LCD, I can specify pen thickness, which is great – no such luck
> in gl.sketch.
> My first thought is to use a blend mode and 2 sketch objects, with
> the “top” sketch object using 2 planes and blendmodes to knockout
> the middle of a plane, and show what’s underneath. This didn’t work.
> My next thought was to use 2 gl.gridshapes with matrix output and
> use jit.op @op – to subtract a smaller plane from a larger one,
> however, the scale message doesn’t seem to affect the matrix
> output! And I’m not sure this would really work anyway…
> I’m stumped. Any thoughts? Has anyone done this before? (BTW, I
> don’t count drawing 4 planes to create a perimeter as “clever” :)
> What I REALLY want to know is if it’s possible to snip up planes
> using other shapes!)
>
> peter.

I’m not sure what visual result you are after.
If you want to use openGl to create the 2D illusion of a picture in a
frame,
then think of it in another way:
draw the frame first — as a solid rectangle,
and then draw the picture on on top of it — centered and slightly
smaller.
although the picture is drawn on top, it creates an illusion of the
picture being in the frame.
If that is what you want.
Hope this helps
-jennek

#99691
Mar 21, 2007 at 7:36pm

sorry for the lack of clarity…what I want is the frame separate from image(s). Besides, it’s not so much the frame I’m after (though that is one thing), but the ability to “snip” out pieces from a plane…

P.

#99692
Mar 21, 2007 at 7:44pm

On 21-mrt-2007, at 18:22, pnyboer wrote:

>
> I’m trying to figure out a clever way to make a thick-lined
> rectangle in sketch, basically creating a frame that something can
> be viewed through, but I’m coming up blank.
> In LCD, I can specify pen thickness, which is great – no such luck
> in gl.sketch.
> My first thought is to use a blend mode and 2 sketch objects, with
> the “top” sketch object using 2 planes and blendmodes to knockout
> the middle of a plane, and show what’s underneath. This didn’t work.
> My next thought was to use 2 gl.gridshapes with matrix output and
> use jit.op @op – to subtract a smaller plane from a larger one,
> however, the scale message doesn’t seem to affect the matrix
> output! And I’m not sure this would really work anyway…
> I’m stumped. Any thoughts? Has anyone done this before? (BTW, I
> don’t count drawing 4 planes to create a perimeter as “clever” :)
> What I REALLY want to know is if it’s possible to snip up planes
> using other shapes!)
>
> peter.
>

alternatively, you could use as a frame:
a videoplane with a texture that represents the frame.
the edge of the texture would be opaque, the inside transparent.
this texture can be drawn with jit.lcd
since jit.lcd only draws opaquely, this would involve
jit.chromakey to make the inside transparent.
HtH
-jennek

#99693
Mar 21, 2007 at 7:48pm

add an alpha dynamically ? snip meaning transparency?

On Mar 21, 2007, at 8:36 PM, pnyboer wrote:

>
> sorry for the lack of clarity…what I want is the frame separate
> from image(s). Besides, it’s not so much the frame I’m after
> (though that is one thing), but the ability to “snip” out pieces
> from a plane…
>
> P.
> –
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> The Lifespan
> 2 oz brandy
> 1/2 oz orgeat
> 1/2 oz maraschino
> 3/4 oz mix of (meyer) lemon and (yellow) grapefruit juice
> Shake with ice and serve in a Pernod-rinsed cocktail glass

v a d e //

http://www.vade.info
abstrakt.vade.info

#99694
Mar 21, 2007 at 7:53pm

The scale message doesn’t affeect matrix output at all (and neither do
position or rotate). Those are applied to the geometry through the
modelview matrix. The matrixoutput simply sends out the raw geometry
with no transforms applied.

As for “snipping”, texture trickery is probably the most flexible way
to go. Just draw in a matrix and texture a plane with it. Otherwise
you’re going to have to do some “unclever” geometric calculations.

Pen thickness in opengl could potentially be glLineWidth() or simply
drawing quads along a path with a certain width.

wes

On 3/21/07, pnyboer

wrote:
>
> sorry for the lack of clarity…what I want is the frame separate from image(s). Besides, it’s not so much the frame I’m after (though that is one thing), but the ability to “snip” out pieces from a plane…
>
> P.
> –
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> The Lifespan
> 2 oz brandy
> 1/2 oz orgeat
> 1/2 oz maraschino
> 3/4 oz mix of (meyer) lemon and (yellow) grapefruit juice
> Shake with ice and serve in a Pernod-rinsed cocktail glass
>

#99695
Mar 21, 2007 at 8:57pm

here’s a patch that “snips” from a videoplane using jit.lcd to make
the alpha mask and the new two texture blendmodes on OGL-objects.

hth

/*j

>> sorry for the lack of clarity…what I want is the frame separate
>> from image(s). Besides, it’s not so much the frame I’m after
>> (though that is one thing), but the ability to “snip” out pieces
>> from a plane…

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 630 148 198 196617 pensize 10 10 , framerect 0 0 2000 1500;
#P button 441 45 15 0;
#N vpatcher 20 74 620 474;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 242 96 61 196617 route count;
#P window linecount 0;
#P newex 164 116 43 196617 random;
#P outlet 170 172 15 0;
#P inlet 168 70 15 0;
#P inlet 246 70 15 0;
#P connect 1 0 3 0;
#P connect 3 0 2 0;
#P connect 4 0 3 1;
#P connect 0 0 4 0;
#P pop;
#P newobj 441 62 51 196617 p random;
#N vpatcher 20 74 620 474;
#P window setfont “Sans Serif” 9.;
#P newex 51 99 47 196617 t count l;
#P newex 51 71 76 196617 prepend prefix;
#P newex 50 50 76 196617 opendialog fold;
#P inlet 50 30 15 0;
#P outlet 51 135 15 0;
#P connect 1 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 0 0;
#P connect 4 1 0 0;
#P pop;
#P newobj 556 83 78 196617 p select_folder;
#P button 542 83 15 0;
#P newex 485 109 68 196617 prepend read;
#P user ubumenu 440 83 100 196617 0 1 1 0;
#X add bball.mov;
#X add blading.mov;
#X add countdown.mov;
#X add countdown15.mov;
#X add crashtest.mov;
#X add dishes.mov;
#X add dozer.mov;
#X add dvducks.mov;
#X add dvkite.mov;
#X add garbage.mov;
#X add oh.mov;
#X add ozone.mov;
#X add rain.mov;
#X add rca.mov;
#X add redball.mov;
#X add track1.mov;
#X add track2.mov;
#X add traffic.mov;
#X add wheel.mov;
#X types MooV MooV;
#X prefix_set 0 1 ” ” 0;
#X pattrmode 1;
#P objectname ubumenu;
#P comment 593 328 14 196617 |;
#P comment 563 328 14 196617 |;
#P comment 591 337 14 196617 V;
#P comment 561 337 14 196617 V;
#P comment 628 227 106 196617 static: only load once;
#N vpatcher 20 74 620 474;
#P window setfont “Sans Serif” 9.;
#P message 50 114 133 196617 fullscreen $1 , fsmenubar 0;
#P toggle 50 96 15 0;
#P newex 50 74 35 196617 sel 27;
#P newex 50 50 40 196617 key;
#P outlet 50 134 15 0;
#P fasten 1 0 2 0 55 71 55 71;
#P fasten 2 0 3 0 55 93 55 93;
#P fasten 3 0 4 0 55 112 55 112;
#P connect 4 0 0 0;
#P pop;
#P newobj 51 343 73 196617 p fullscreener;
#P message 598 148 30 196617 bang;
#P newex 598 192 148 196617 jit.fastblur @mode 2 @range 3;
#P objectname jit.lcd[2];
#P comment 623 334 182 196617 note that two textures are called here;
#P window linecount 2;
#P newex 394 262 173 196617 jit.gl.texture context @name source
@colormode uyvy;
#P objectname jit.gl.texture[1];
#P user jit.fpsgui 51 254 60 196617 0;
#P objectname jit.fpsgui;
#P window linecount 1;
#P newex 394 83 41 196617 r pulse;
#P objectname receive;
#P newex 75 179 41 196617 s pulse;
#P newex 394 174 146 196617 jit.qt.movie @colormode uyvy;
#P objectname jit.qt.movie;
#P message 119 180 34 196617 reset;
#P newex 119 199 202 196617 jit.gl.handle context @inherit_transform 1;
#P objectname jit.gl.handle;
#P toggle 51 73 15 0;
#P objectname toggle;
#P newex 51 366 297 196617 jit.window context @floating 1
@depthbuffer 1 @doublebuffer 1;
#P objectname jit.window;
#P newex 51 233 215 196617 jit.gl.render context @erase_color 0. 0.
0. 1.;
#P objectname jit.gl.render;
#P newex 51 147 58 196617 t b b erase;
#P newex 51 95 57 196617 qmetro 33;
#P newex 51 390 114 196617 autopattr @autoname 1;
#X prestore toggle 1 0 1;
#X prestore ubumenu 1 0 dvducks.mov;
#P objectname u394000032;
#P newex 598 115 48 196617 loadbang;
#P window linecount 2;
#P newex 598 260 226 196617 jit.gl.texture context @name mask @mode
static @colormode intensity;
#P objectname jit.gl.texture[2];
#P window setfont “Sans Serif” 18.;
#P window linecount 1;
#P comment 40 32 365 196626 applying two textures to one videoplane;
#P window setfont “Sans Serif” 9.;
#P comment 627 213 121 196617 oversampled and blurred;
#P newex 395 353 382 196617 jit.gl.videoplane context @texture source
mask @blend_enable 1 @scale 1. 0.75 1.;
#P objectname jit.gl.texture;
#P newex 598 171 123 196617 jit.lcd 4 char 2000 1500;
#P objectname jit.lcd[1];
#P connect 5 0 21 0;
#P connect 5 0 34 0;
#P connect 21 0 0 0;
#P connect 0 0 20 0;
#P connect 34 0 0 0;
#P connect 20 0 4 0;
#P hidden connect 30 0 31 0;
#P connect 28 1 29 0;
#P fasten 28 2 32 1 535 104 637 104 637 43 487 43;
#P connect 33 0 32 0;
#P hidden connect 31 0 28 0;
#P connect 32 0 28 0;
#P connect 14 0 18 0;
#P connect 29 0 14 0;
#P connect 16 0 14 0;
#P connect 13 0 12 0;
#P connect 8 1 15 0;
#P connect 22 0 10 0;
#P connect 9 0 17 0;
#P connect 8 0 9 0;
#P connect 8 2 9 0;
#P connect 12 0 9 0;
#P connect 7 0 8 0;
#P connect 11 0 7 0;
#P window clipboard copycount 35;

#99696
Mar 21, 2007 at 10:25pm

@colormode intensity?

Is there a better list to describe what these colormodes do? They do
not match the OpenGL blend modes, do they? Thanks,

On Mar 21, 2007, at 9:57 PM, jasch wrote:

> here’s a patch that “snips” from a videoplane using jit.lcd to make
> the alpha mask and the new two texture blendmodes on OGL-objects.
>
> hth
>
> /*j
>
>>> sorry for the lack of clarity…what I want is the frame separate
>>> from image(s). Besides, it’s not so much the frame I’m after
>>> (though that is one thing), but the ability to “snip” out pieces
>>> from a plane…
>
> #P window setfont “Sans Serif” 9.;
> #P window linecount 1;
> #P message 630 148 198 196617 pensize 10 10 , framerect 0 0 2000
> 1500;
> #P button 441 45 15 0;
> #N vpatcher 20 74 620 474;
> #P window setfont “Sans Serif” 9.;
> #P window linecount 1;
> #P newex 242 96 61 196617 route count;
> #P window linecount 0;
> #P newex 164 116 43 196617 random;
> #P outlet 170 172 15 0;
> #P inlet 168 70 15 0;
> #P inlet 246 70 15 0;
> #P connect 1 0 3 0;
> #P connect 3 0 2 0;
> #P connect 4 0 3 1;
> #P connect 0 0 4 0;
> #P pop;
> #P newobj 441 62 51 196617 p random;
> #N vpatcher 20 74 620 474;
> #P window setfont “Sans Serif” 9.;
> #P newex 51 99 47 196617 t count l;
> #P newex 51 71 76 196617 prepend prefix;
> #P newex 50 50 76 196617 opendialog fold;
> #P inlet 50 30 15 0;
> #P outlet 51 135 15 0;
> #P connect 1 0 2 0;
> #P connect 2 0 3 0;
> #P connect 3 0 4 0;
> #P connect 4 0 0 0;
> #P connect 4 1 0 0;
> #P pop;
> #P newobj 556 83 78 196617 p select_folder;
> #P button 542 83 15 0;
> #P newex 485 109 68 196617 prepend read;
> #P user ubumenu 440 83 100 196617 0 1 1 0;
> #X add bball.mov;
> #X add blading.mov;
> #X add countdown.mov;
> #X add countdown15.mov;
> #X add crashtest.mov;
> #X add dishes.mov;
> #X add dozer.mov;
> #X add dvducks.mov;
> #X add dvkite.mov;
> #X add garbage.mov;
> #X add oh.mov;
> #X add ozone.mov;
> #X add rain.mov;
> #X add rca.mov;
> #X add redball.mov;
> #X add track1.mov;
> #X add track2.mov;
> #X add traffic.mov;
> #X add wheel.mov;
> #X types MooV MooV;
> #X prefix_set 0 1 ” ” 0;
> #X pattrmode 1;
> #P objectname ubumenu;
> #P comment 593 328 14 196617 |;
> #P comment 563 328 14 196617 |;
> #P comment 591 337 14 196617 V;
> #P comment 561 337 14 196617 V;
> #P comment 628 227 106 196617 static: only load once;
> #N vpatcher 20 74 620 474;
> #P window setfont “Sans Serif” 9.;
> #P message 50 114 133 196617 fullscreen $1 , fsmenubar 0;
> #P toggle 50 96 15 0;
> #P newex 50 74 35 196617 sel 27;
> #P newex 50 50 40 196617 key;
> #P outlet 50 134 15 0;
> #P fasten 1 0 2 0 55 71 55 71;
> #P fasten 2 0 3 0 55 93 55 93;
> #P fasten 3 0 4 0 55 112 55 112;
> #P connect 4 0 0 0;
> #P pop;
> #P newobj 51 343 73 196617 p fullscreener;
> #P message 598 148 30 196617 bang;
> #P newex 598 192 148 196617 jit.fastblur @mode 2 @range 3;
> #P objectname jit.lcd[2];
> #P comment 623 334 182 196617 note that two textures are called here;
> #P window linecount 2;
> #P newex 394 262 173 196617 jit.gl.texture context @name source
> @colormode uyvy;
> #P objectname jit.gl.texture[1];
> #P user jit.fpsgui 51 254 60 196617 0;
> #P objectname jit.fpsgui;
> #P window linecount 1;
> #P newex 394 83 41 196617 r pulse;
> #P objectname receive;
> #P newex 75 179 41 196617 s pulse;
> #P newex 394 174 146 196617 jit.qt.movie @colormode uyvy;
> #P objectname jit.qt.movie;
> #P message 119 180 34 196617 reset;
> #P newex 119 199 202 196617 jit.gl.handle context
> @inherit_transform 1;
> #P objectname jit.gl.handle;
> #P toggle 51 73 15 0;
> #P objectname toggle;
> #P newex 51 366 297 196617 jit.window context @floating 1
> @depthbuffer 1 @doublebuffer 1;
> #P objectname jit.window;
> #P newex 51 233 215 196617 jit.gl.render context @erase_color 0. 0.
> 0. 1.;
> #P objectname jit.gl.render;
> #P newex 51 147 58 196617 t b b erase;
> #P newex 51 95 57 196617 qmetro 33;
> #P newex 51 390 114 196617 autopattr @autoname 1;
> #X prestore toggle 1 0 1;
> #X prestore ubumenu 1 0 dvducks.mov;
> #P objectname u394000032;
> #P newex 598 115 48 196617 loadbang;
> #P window linecount 2;
> #P newex 598 260 226 196617 jit.gl.texture context @name mask @mode
> static @colormode intensity;
> #P objectname jit.gl.texture[2];
> #P window setfont “Sans Serif” 18.;
> #P window linecount 1;
> #P comment 40 32 365 196626 applying two textures to one videoplane;
> #P window setfont “Sans Serif” 9.;
> #P comment 627 213 121 196617 oversampled and blurred;
> #P newex 395 353 382 196617 jit.gl.videoplane context @texture
> source mask @blend_enable 1 @scale 1. 0.75 1.;
> #P objectname jit.gl.texture;
> #P newex 598 171 123 196617 jit.lcd 4 char 2000 1500;
> #P objectname jit.lcd[1];
> #P connect 5 0 21 0;
> #P connect 5 0 34 0;
> #P connect 21 0 0 0;
> #P connect 0 0 20 0;
> #P connect 34 0 0 0;
> #P connect 20 0 4 0;
> #P hidden connect 30 0 31 0;
> #P connect 28 1 29 0;
> #P fasten 28 2 32 1 535 104 637 104 637 43 487 43;
> #P connect 33 0 32 0;
> #P hidden connect 31 0 28 0;
> #P connect 32 0 28 0;
> #P connect 14 0 18 0;
> #P connect 29 0 14 0;
> #P connect 16 0 14 0;
> #P connect 13 0 12 0;
> #P connect 8 1 15 0;
> #P connect 22 0 10 0;
> #P connect 9 0 17 0;
> #P connect 8 0 9 0;
> #P connect 8 2 9 0;
> #P connect 12 0 9 0;
> #P connect 7 0 8 0;
> #P connect 11 0 7 0;
> #P window clipboard copycount 35;
>
>
>

v a d e //

http://www.vade.info
abstrakt.vade.info

#99697
Mar 21, 2007 at 10:32pm

hmm…ok, lots of information here…I should have said “using textures is not clever”. Of course that’s an absurd statement, but was the context I was after. I think wes put it best:
[quote]As for “snipping”, texture trickery is probably the most flexible way to go. Just draw in a matrix and texture a plane with it. Otherwise you’re going to have to do some “unclever” geometric calculations.[/quote]
thanks for all the suggestions, though, as they are good demonstrations of reasonable alternatives.

#99698
Mar 21, 2007 at 10:33pm

They correspond to texture internal formats which roughly corresponds
to the number of planes of the input matrix.

Here’s a doc, but not incredibly helpful. It does show where the name
comes from though.

http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/glTexImage2D.3.html

wes

#99699
Mar 22, 2007 at 12:12am

Peter,
The really clever way would be to use a shader that takes advantage of
the “discard” command (which might not be supported on some cards).
Here is a little example I cooked up recently that discards pixels
according to a goofy mathematical function run on the texture
coordinates. The nice thing about “discard” is that it’ll work whether
blending is enabled or not.
The shader is attached.

Andrew B.

Here is the patch:

#P window setfont “Sans Serif” 9.;
#P flonum 539 66 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 503 66 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 467 66 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 431 66 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 431 84 119 196617 pak param fig 1. 1. 1. 1.;
#P flonum 496 114 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 431 132 100 196617 pak param thresh 0.;
#P message 440 165 30 196617 read;
#P newex 431 188 212 196617 jit.gl.shader fa @file ab.plop.jxs @name doop;
#B color 5;
#P newex 21 145 70 196617 jit.window fa;
#P newex 158 149 254 196617 jit.gl.videoplane fa @transform_reset 2
@shader doop;
#P newex 21 123 121 196617 jit.gl.render fa @ortho 2;
#P newex 21 79 58 196617 t b b erase;
#P message 274 75 27 196617 stop;
#P flonum 305 55 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 305 75 42 196617 rate $1;
#P message 242 75 28 196617 read;
#P flonum 62 37 35 9 0.5 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 21 37 15 0;
#P newex 21 58 51 196617 qmetro 2;
#P newex 158 127 144 196617 jit.qt.movie 320 240;
#P connect 0 0 10 0;
#P connect 16 0 12 0;
#P connect 13 0 12 0;
#P connect 14 0 12 0;
#P connect 15 0 14 2;
#P connect 17 0 16 2;
#P connect 18 0 16 3;
#P connect 19 0 16 4;
#P connect 20 0 16 5;
#P fasten 8 1 0 0 50 117 163 117;
#P connect 6 0 5 0;
#P fasten 5 0 0 0 310 117 163 117;
#P fasten 7 0 0 0 279 117 163 117;
#P fasten 4 0 0 0 247 117 163 117;
#P connect 3 0 1 1;
#P fasten 8 2 9 0 74 105 26 105;
#P connect 8 0 9 0;
#P connect 1 0 8 0;
#P connect 2 0 1 0;
#P window clipboard copycount 21;


liquid texture manipulations





< ![CDATA[

varying vec3 N;
varying vec3 P;

varying vec3 f;
varying vec2 texcoord0;

void main (void)

{
P = normalize((gl_ModelViewMatrix*gl_Vertex).xyz);
N = normalize(gl_NormalMatrix*gl_Normal);
gl_Position = ftransform();
texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
}

]]>

< ![CDATA[

uniform vec4 fig;
varying vec3 N;
varying vec3 P;

uniform float thresh;

uniform sampler2DRect tex0;

varying vec2 texcoord0;

void main (void)
{

vec2 pee = texcoord0;

vec4 poo = fig*vec4(0.01);
vec2 ape = sin(pee*poo.xy+poo.ww)+cos(pee*poo.yz+poo.xx);
float goop = dot(ape,vec2(1.));

if (goop < thresh) discard;

vec4 a = texture2DRect(tex0,texcoord0);

gl_FragColor = a;
}
]]>

#99700
Mar 22, 2007 at 12:24am

maybe a bit OT but
how about some good old CSG?
subtract one cube from another

in this link they’ve done it realtime in java

http://www.geocities.com/danbalby/

you can dl the source
i dont know java but maybe someone else ?

-mj

>They correspond to texture internal formats which roughly corresponds
>to the number of planes of the input matrix.
>
>Here’s a doc, but not incredibly helpful. It does show where the name
>comes from though.
>http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/glTexImage2D.3.html
>
>wes

#99701

You must be logged in to reply to this topic.