Forums > Java

Cannot render text on top of sketch and texture

Jun 28 2009 | 7:27 am

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


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. —
Jun 30 2009 | 4:10 pm

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 …

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

Forums > Java