Forums > Java

Is jit.gl.slab functionality within Java possible?


May 11, 2012 | 1:47 am

Hi list,

I want to make a java wrapper for the jit.gl.slab object to make some slab thingies easier to do.

But I immediately run into a fundamental problem: I can’t get the input and output of a jit.gl.slab object work.

I basically did this:
1. I instantiated a JitterObject with ‘ new JitterObject("jit.gl.slab") ‘.
2. I made the ‘anything’ method forward all incoming data to this JitterObject via the ‘call’ method.
3. I set up a JitterListener to listen to outcoming textures when the slab is done processing them.

The JitterListener however doesn’t seem to register the out coming ‘jit_gl_texture’ messages.

Also, when I use the ‘call’ method, no Atom[] array is returned, in stead I get only null.

So much for the straightforward solution.
So I tried sending out the resulting textures (with their names defined in the ‘capture’ attribute) simply after receiving incoming jit.matrices. That only gives me a black window.
So I tried sending out the resulting textures after any of the messages that the JitterListener dóes register. Still no luck.

As you can see in the java file (attached) and the max patch (I tried to comment it all quite clearly), I’ve tried basically every point that I could think of to send out the resulting texture. Without success.

Can anybody tell me how to make a shader / slab work within Java code?

Thank you to anyone pointing me in the right direction!

- tarik

– Pasted Max Patch, click to expand. –
Attachments:
  1. SlabWrap.java
May 11, 2012 | 9:47 am

There’s a get-only attribute called out_name that will give you the name of the jit.gl.texture that is the slab’s output. You can use its value to chain together slabs and texture other jit.gl objects. You can use the relevant attr getting java methods to get its value, but here’s a patcher version:

– Pasted Max Patch, click to expand. –
May 11, 2012 | 10:43 am

Thanks! But the ‘out_name’ attribute gives the exact same name as the ‘capture’ attribute that I send out through the mxj outlet. So the outcoming textures are named correctly I believe. Only, for some reason, they are empty at the moment that I send them. (btw, just to be sure, I just now tested the use of the out_name attribute in my Java file, which as expected gave the same results).
I think there might be a timing problem: I might be sending out the texture while its being created, or right before or something.

I believe I would be helped a lot if a JitterListener could actually see when the jit.gl.slab object sends out the resulting texture. But for some reason it seems to ignore this.

May 11, 2012 | 11:01 am

Oh wow, I found the staggeringly simple answer:

In ‘normal’ max, sending a jit.gl.slab object a matrix or a texture will make it automatically process a texture.

Within Java however, this does NOT happen automatically. The texture does not get drawn until you explicity give it the "draw" command.

A subtle inconsistency which got me thinking in waaay too complex ways.

January 13, 2015 | 2:50 pm

hi Tarik,
I know this topic is a bit old, but it is so hard to find anything about jitter and java when you want to do more than the basic example in the doc.

I’m trying to do the same thing and did make the "draw" call but it won’t display anything.
Could you share your java code please?

I’ve posted my problem here too

I could only make the jit.gl.texture display something.
I then replace jit.gl.texture by a jit.gl.slab exactly the same way but it won’t display anything.

January 13, 2015 | 3:23 pm

Hi Robotpapier,

here an example from off the top of my head.

JitterObject slab = new JitterObject("jit.gl.slab", "renderContext");
JitterObject hapPlayer = new JitterObject("jit.gl.hap", "renderContext");

public void bang(){
slab.call("jit_gl_texture", hapPlayer.getAttr("out_name");
slab.call("draw");
outlet(0, "jit_gl_texture", slab.getAttr("out_name");
}

public void read(String filePath){
hapPlayer.call("read", filePath);
}

This should copy a texture from the jit.gl.hap to jit.gl.slab and output it from outlet 0. Of course you have to replace "renderContext" with the actual name of your render context…

Hope it helps.

January 13, 2015 | 5:26 pm

Hi Django! You are a lifesaver, was about to let down the java version of my patch and was kinda sad, but you made my day and I’m back in da game again :), thanks!

Besides i’m working on Max 6 and am trying Max 7 too,
the same java code works on Max 6 but not on Max 7 32 bits.
I’ve checked that in "patcher mode" jit.gl.hap is working.

Here is the working class for Max 6.1 32 bits Windows for hap player :


public class myHapClass extends MaxObject {
	private JitterObject myWindow; 
	private JitterObject myHapMovie;
	private JitterObject myVideoplane;
	private JitterObject myRender;

	public myHapClass(){	
		declareInlets(new int[]{ DataTypes.ANYTHING}); 
		declareOutlets(new int[]{ DataTypes.ANYTHING});

		// jit.window
		this.myWindow = new JitterObject("jit.window","myWindow");		
		this.myWindow.setAttr("depthbuffer", 0); 	
		this.myWindow.setAttr("fsaa", 1);

		//jit.gl.videoplane
		this.myVideoplane = new JitterObject("jit.gl.videoplane","myWindow");
		this.myVideoplane.setAttr("transform_reset", 2);

		// jit.gl.render
		this.myRender = new JitterObject("jit.gl.render","myWindow");
		this.myRender.setAttr("erase_color", new int[] {0,0,0,1} );

		// jit.gl.hap
		this.myHapMovie = new JitterObject("jit.gl.hap");		
		this.myHapMovie.send("read","myHapMovie.mov");
		this.myHapMovie.setAttr("drawto", "myWindow"); // won't work if the context is not set
		this.myHapMovie.send("start");
		// this.myHapMovie.setAttr("autostart", 0); // I've also tested this mentionned in another post but it doesn't change anything

	}
	
	public void bang() {
		this.myHapMovie.call("draw");
		this.myRender.call("erase");
		this.myVideoplane.call("jit_gl_texture",this.myHapMovie.getAttr("out_name")); 
		this.myRender.call("drawclients");
		this.myRender.call("swap");
	}
}

Max 6 works but Max 7 displays blank black screen, did you by chance tried hap on Max 7 and if yes knows what could be the problem?

January 13, 2015 | 5:46 pm

ohh, sorry, it’s working now, was just a path problem ^^

January 14, 2015 | 5:32 pm

Re,
just wanted to report that although this.myHapMovie.freePeer() draws an error in the max console (jit.gl: invalid extension called), it is effectively freed.

Not freeing the object won’t draws the error but will cause crash if the object is reused.

January 15, 2015 | 9:34 am

that error can be ignored.

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

Forums > Java