Cannot render jit.gl.text3d text on top of sketch and texture

wijesijp's icon

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 anyone 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;
}
}
Max Patch
Copy patch and select New From Clipboard in Max.

wijesijp's icon

I have seen posts saying this can be rectified by setting automatic and z order
I think I have done it properly. But it is not working ...