mask in gl / depth problem

Apr 4, 2009 at 7:14am

mask in gl / depth problem

Hi all,

i want to create something like this:
http://dump.sylvain.nl/random/squarycircle.png

The video is a jit.gl.videoplane, 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 jit.gl.sketch to draw a flattened torus with a big enough hole in the middle.

Problem: I am also drawing text to the window with a jit.gl.text2d 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.

#43196
Apr 4, 2009 at 11:28am

hello
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…

best
Alex

#154880
Jul 2, 2009 at 5:49am

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″});

createInfoOutlet(false);

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(“jit.gl.render”, “draw_plane”);
myrender.setAttr(“erase_color”, new float[] {0.0f,0.0f,0.0f,1.0f });
myrender.setAttr(“automatic “, 0);

sketch = new JitterObject(“jit.gl.sketch”);
sketch.setAttr(“automatic “, 0);

displayText = new JitterObject(“jit.gl.text3d”);
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(“jit.gl.texture”);
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(“glpushmatrix”);
sketch.send(“glpushattrib”);
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(“glend”);

sketch.send(“gldisable”, “texture”);
sketch.send(“glpopattrib”);
sketch.send(“glpopmatrix”);
}

private void DrawColorSquare(float[] vo1,float[] vo2,float[] vo3,float[] vo4,float r, float g,float b)
{
sketch.send(“glpushmatrix”);
sketch.send(“glpushattrib”);

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);
sketch.send(“glend”);

sketch.send(“glpopattrib”);
sketch.send(“glpopmatrix”);
}

public void draw()
{
myrender.send(“erase”);
myrender.send(“drawclients”);
myrender.send(“drawswap”);

sketch.setAttr(“drawto”, “draw_plane”);
sketch.setAttr(“depth_enable”, 1);
sketch.setAttr(“lighting_enable”, 0);
sketch.setAttr(“antialias”, 1);
sketch.send(“reset”);

sketch.send(“glmatrixmode”,new Atom[]{Atom.newAtom(“projection”)});
sketch.send(“glloadidentity”);
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(“glloadidentity”);
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.freePeer();
sketch = null;
texture.freePeer();
texture = null;
displayText.freePeer();
displayText = null;
myrender.freePeer();
myrender = null;
window.freePeer();
window = null;
}
}

– Pasted Max Patch, click to expand. –
#154881
Jul 2, 2009 at 6:01am

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

#154882
Jul 3, 2009 at 5:04pm

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.

#154883
Jul 3, 2009 at 5:07pm

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

#154884

You must be logged in to reply to this topic.