Forums > Jitter

Loading a jit.gl.texture programmatically

April 23, 2009 | 7:51 am

I have written a java external that draw some objects in a scene. I want to set a textures for the objects.
I can create a texture object like
texture = new JitterObject("jit.gl.texture");
but I don’t know how to load the texture file or how to use that texture on a object
can you help?


April 23, 2009 | 12:59 pm

you might want to post in the jitter developer forum rather then the jitter user forum


April 26, 2009 | 5:44 am

texture.read(filename) will read a file. object.texture = texture.name will attach a texture to an object. I don’t remember the exact syntax, but this is the gist of it.

wes


April 26, 2009 | 5:33 pm

If I am not mistaken that is how you do it if you are programming using javascript.
I wanted to do it using Java external. Any idea how to do that?


April 27, 2009 | 5:51 pm

I believe it’s nearly identical.
wes


April 30, 2009 | 6:40 pm

I have written simple JavaScript program to load a textures and rotate the plane after looking at several examples in the forum
When I run it the program does work but I can see some white squares flickering all over the window and loaded texture looks different.
Any suggestions?

inlets = 1;
outlets = 1;

//jit window
var mywindow = new JitterObject("jit.window","test");
mywindow.depthbuffer = 1;
mywindow.doublebuffer = 1;
mywindow.size = [1000,800];
//mywindow.idlemouse = 0;
//mywindow.mode = "texture"
//mywindow.interp = 1;

//render
var myrender = new JitterObject("jit.gl.render","test");
myrender.ortho = 2;
myrender.camera =[0, -10, 20];
myrender.lookat= [0, 0, 0];
myrender.far_clip = 1000;
myrender.erase_color = [0,0,0,1];

var mywallpaper = new JitterObject("jit.gl.texture","test");
mywallpaper.name = "wallpaper";
mywallpaper.read("skin2.tif");

var planepaper = new JitterObject("jit.gl.gridshape","test");
planepaper.shape = "plane";
planepaper.lighting_enable = 1;
planepaper.smooth_shading = 1;
planepaper.color = [1,1,1,1];
planepaper.position = [0,0];
planepaper.blend_enable = 1;
planepaper.texture = "wallpaper";

var small_amt = 1.1;
var ang =0;

function bang()
{

ang += small_amt ;
if (ang > 360)
ang -= 360;

planepaper.rotate = [ang, 0, 0, 1];

myrender.erase();
myrender.drawclients();
myrender.swap();

}


April 30, 2009 | 9:05 pm

please provide a simple patch that loads your javascript file and illustrates the problem.


April 30, 2009 | 9:22 pm

Please find the attached file
Somehow the flickering no longer appearing now. I have no idea how it happened only thing I did was close and restart max/msp program.

However the texture still looks somewhat bluish


April 30, 2009 | 9:23 pm

{
"boxes" : [ {
"box" : {
"maxclass" : "newobj",
"text" : "js mytest.js",
"outlettype" : [ "" ],
"fontsize" : 12.0,
"patching_rect" : [ 52.0, 133.0, 68.0, 22.0 ],
"numinlets" : 1,
"fontname" : "Arial",
"numoutlets" : 1,
"id" : "obj-1"
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "t b erase",
"outlettype" : [ "bang", "erase" ],
"fontsize" : 10.024474,
"patching_rect" : [ 52.0, 89.0, 56.0, 20.0 ],
"numinlets" : 1,
"fontname" : "Arial",
"numoutlets" : 2,
"id" : "obj-8"
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "qmetro 40",
"outlettype" : [ "bang" ],
"fontsize" : 10.024474,
"patching_rect" : [ 52.0, 52.0, 63.0, 20.0 ],
"numinlets" : 2,
"fontname" : "Arial",
"numoutlets" : 1,
"id" : "obj-34"
}

}
, {
"box" : {
"maxclass" : "toggle",
"outlettype" : [ "int" ],
"patching_rect" : [ 52.0, 25.0, 20.0, 20.0 ],
"numinlets" : 1,
"numoutlets" : 1,
"id" : "obj-35"
}

}
],
"lines" : [ {
"patchline" : {
"source" : [ "obj-34", 0 ],
"destination" : [ "obj-8", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-35", 0 ],
"destination" : [ "obj-34", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-8", 0 ],
"destination" : [ "obj-1", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
]
}


April 30, 2009 | 9:35 pm

I have taken a screenshot of the window. The bottom image is the actual image and the top one is how the max engendered it. It is quite bluish …


April 30, 2009 | 9:38 pm

your patch works as expected over here. if the color looks off, try lighting_enable 0.

also, please post patches using the Edit – Copy compressed option.


April 30, 2009 | 9:59 pm

When I change this line I noticed that only some brightness changes
planepaper.lighting_enable = 0;
didn’t fixed the problem …
when I changed the following line I noticed big changes in the images appearance. Still the problem is there
planepaper.color = [1,1,0,1];
then I set the following line to change the lighting of the renderer still no change
myrender.lighting_enable = 0;
is there any other settings I should try?


April 30, 2009 | 10:26 pm

not sure what the problem is, but it looks like the color planes are re-mapped. the image in your screenshot is not the same as the image you posted in your zip file.

can you post the image from the screenshot as well as relevant system specs?


April 30, 2009 | 10:41 pm

Yes I took the screen shot with a different image. Following is a screen shot of the image in the zip file.
As you can see it is somewhat blue colored.
I am running
windows vista ultimate
Intel core 2 quad cpu/ 4gb ram
nvidia geforce gtx 260


April 30, 2009 | 11:32 pm

maybe try with a jpg or png?


May 1, 2009 | 4:37 am

I tried jpg and it looks the same.
Do you have a sample code that does something like this so I can have look to see what I did wrong?


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