The shader was in the first post, but I changed it so a shader is not needed anymore.
Stencils can be used to discard fragments (pixels). In the above example the outline is drawn after the box is drawn and not the other way around. I need to use stencils for clipping cause the opengl scissor does not work under an angle.
I don’t get it. Your code says sh = loadShader("single_color.glsl"); but you don’t provide a link to a glsl file, or the contents of that file. If you don’t need it, why are you loading it? If you do need it, can you share it?
I have never used beginPGL / endPGL in a sketch before – it took me a while to figure out how the sketch builds the scene in three stages (the platform, the box, and the unlit scaled red box to appear “behind” it). Particularly interesting that the outline effect is a 3D object that then aligns correctly through compositing.
If I was diving deeper into this stuff, I would probably begin reading here…
For my own understanding I created an annotated version of this that lets you scale the box and outline interactively using mouseX / mouseY.
The outline is impressive – although the illusion breaks a bit if they both cross too far into the platform and you start seeing them double-intersecting.