Forums > Jitter

mask in gl / depth problem

Apr 04 2009 | 7:14 am

Hi all,

i want to create something like this:

The video is a, the idea is to have a peephole which grows over time and shows more of the video (without scaling it). In this example i used to draw a flattened torus with a big enough hole in the middle.

Problem: I am also drawing text to the window with a object. But this always ends up between the videoplane and the sketch layer. All objects have automatic switched off, and are drawn in the right order.

Sorry, no example, i am doing it in java at the moment.

Apr 04 2009 | 11:28 am

I would position your objects one in front of another (with position message) and set layers 0 1 2… in corresponding order.
then You don’t need to switch automatic off even.
Don’t forget camera and lookat right order as well.
also I think You don’t need to draw torus, draw circle in lcd or jit.lcd, change radius and apply the matrix as alpha channel of the videoplane input…
another funny thing might be two skethes – plane as a solid surface and circle as a hole. circle placed in front of plane will make this area of plane transparent…


Jul 02 2009 | 5:49 am

I have a similar problem in my application.
In my application I have some objects drawn using sketch and some textures rendered using "quads" I wanted to place some text on top of all that.
I have set the z order properly but I cannot get the text rendered on top of sketch or texture.
Can you guys provide some help?

import com.cycling74.max.*;
import com.cycling74.jitter.*;
import com.cycling74.max.Atom;

public class Calibration extends MaxObject
JitterObject sketch;
JitterObject texture;
JitterObject window;
JitterObject myrender;
JitterObject displayText;

float cube_side             = 2.5f;
float[] v1 = new float[]{ -cube_side, -cube_side,  0 };
float[] v2 = new float[]{  cube_side, -cube_side,  0 };
float[] v3 = new float[]{  cube_side,  cube_side,  0 };
float[] v4 = new float[]{ -cube_side,  cube_side,  0 };

int windowWidth 		= 1024;
int windowHeight	 	= 800;

public Calibration()
declareInlets(new int[]{ DataTypes.ALL, DataTypes.ALL,DataTypes.ALL});
declareOutlets(new int[]{ DataTypes.ALL, DataTypes.ALL,DataTypes.ALL});
setInletAssist(new String[] { "bang to output"," to check block in region"," to check block in active region"});
setOutletAssist(new String[] { "workspace test results"," result of input to inlet 2","  result of input to inlet 3"});


window              = new  JitterObject("jit.window", "draw_plane");
window.setAttr("depthbuffer", 1);
window.setAttr("doublebuffer", 1);
window.setAttr("size",  new int[] {windowWidth,windowHeight });

myrender            = new  JitterObject("", "draw_plane");
myrender.setAttr("erase_color",  new float[] {0.0f,0.0f,0.0f,1.0f });
myrender.setAttr("automatic ", 0);

sketch              = new JitterObject("");
sketch.setAttr("automatic ", 0);

displayText         = new JitterObject("");
displayText.setAttr("drawto", "draw_plane");
displayText.setAttr("align", 1);
displayText.setAttr("color", new float[]{ 0.65f,0.65f,0.65f });
displayText.setAttr("position", new float[]{ 0.0f,0.0f,-10.0f });
displayText.setAttr("font", new Atom[] { Atom.newAtom("Arial"), Atom.newAtom("5") });
displayText.setAttr("automatic ", 0);
displayText.send("text", new Atom[] { Atom.newAtom("Step 1") });
displayText.send("scale", new float[]{1.0f,1.0f,1.0f});

texture             = new JitterObject("");
texture.setAttr("drawto", "draw_plane");
texture.setAttr("name", "tex2");
texture.setAttr("automatic ", 0);


public void InitApp()
texture.send("read", new Atom[] { Atom.newAtom("cube_skin.tif") });

public void bang()

private void DrawBlock(float x,float y,float z,float scale,int angle,float tex_x1,float tex_y1,float tex_x2,float tex_y2)
sketch.send("glenable", "texture");
sketch.send("glbindtexture", "tex2");

sketch.send("gltranslate", new float[]{ x, y, z });
sketch.send("glrotate", new float[]{ angle, 0, 0,1 });
sketch.send("glscale", new float[]{ scale, scale,scale });

sketch.send("glbegin", "quads");
sketch.send("gltexcoord", new float[]{ tex_x1,  tex_y1 });
sketch.send("glvertex", v1);
sketch.send("gltexcoord", new float[]{ tex_x2,  tex_y1 });
sketch.send("glvertex", v2);
sketch.send("gltexcoord", new float[]{ tex_x2,  tex_y2 });
sketch.send("glvertex", v3);
sketch.send("gltexcoord", new float[]{ tex_x1,  tex_y2 });
sketch.send("glvertex", v4);


sketch.send("gldisable", "texture");

private void DrawColorSquare(float[] vo1,float[] vo2,float[] vo3,float[] vo4,float r, float g,float b)

sketch.send("glcolor", new float[]{r,g,b});
sketch.send("glbegin", "quads");
sketch.send("glvertex", vo1);
sketch.send("glvertex", vo2);
sketch.send("glvertex", vo3);
sketch.send("glvertex", vo4);


public void draw()

sketch.setAttr("drawto", "draw_plane");
sketch.setAttr("depth_enable", 1);
sketch.setAttr("lighting_enable", 0);
sketch.setAttr("antialias", 1);

sketch.send("glmatrixmode",new Atom[]{Atom.newAtom("projection")});
sketch.send("glortho", new Atom[]{Atom.newAtom(-128.0f),Atom.newAtom(128.0f),Atom.newAtom(-100.0f),Atom.newAtom(100.0f),Atom.newAtom(0.0f),Atom.newAtom(1000.0f)});
sketch.send("glmatrixmode",new Atom[]{Atom.newAtom("modelview")});
sketch.send("glenable",new Atom[]{Atom.newAtom("depth_test")});
sketch.send("glshademodel",new Atom[]{Atom.newAtom("smooth")});

float[] v1b = new float[]{ -10.0f,-10.0f, -90.0f };
float[] v2b = new float[]{  10.0f,-10.0f, -90.0f };
float[] v3b = new float[]{  10.0f, 10.0f, -90.0f };
float[] v4b = new float[]{ -10.0f, 10.0f, -90.0f };

DrawColorSquare(v1b, v2b, v3b, v4b, 1.0f, 1.0f, 1.0f);
DrawBlock(10.0f, 0, -50.0f, 5,0, 0.0f, 0.0f, 1.0f,1.0f);


public void notifyDeleted()
sketch = null;
texture = null;
displayText = null;
myrender = null;
window = null;

— Pasted Max Patch, click to expand. —
Jul 02 2009 | 6:01 am

Onandoff, I am not really clear what you mean by layers
Can you explain a little how to set the layers?

Jul 03 2009 | 5:04 pm

layer is an attribute of all gl objects. they are only useful in automatic mode, and cause objects to be depth ordered based on their layer number. best way to understand is to experiment with it.

Jul 03 2009 | 5:07 pm

So can I set it like this?
displayText.setAttr("layer", 1);

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

Forums > Jitter