Forums > Javascript

javascript gl.sketch problem


Oct 15 2012 | 3:46 pm

hi, i try to figure out why i didn’t see the light effect? its an pyramid in open gl but it looks flat without the light. can anybody give me an advice, where the failure is and how to adjust the light position? thx.
you only need to save the script to an js object and send a "draw" message to the object.

the script::
autowatch = 1;
inlets = 1;

var windowout = new JitterObject("jit.window","Sketchrender");
windowout.depthbuffer = 0;
windowout.idlemouse = 1;
windowout.fsaa = 1;

var render = new JitterObject("jit.gl.render","Sketchrender");
render.ortho = 1;
render.erase_color = [0,0,0,1];
var Objekt = [-0.5,-0.5,0,-0.5,0.5,0,0.5,0.5,0,0.5,-0.5,0,-0.5,-0.5,0];

function draw(){
var sketch = new JitterObject("jit.gl.sketch","Sketchrender");
sketch.glbegin("triangles");
sketch.gllightmodel("two_side", "true");
sketch.glenable("lighting");
sketch.glenable("light0");
sketch.glcolor(1,1,1,1);
for(j = 0; j < 4;j++){
sketch.glvertex(0,0,1);
sketch.glvertex(Objekt[(j*3) + 0],Objekt[(j*3) + 1],Objekt[(j*3) + 2]);
sketch.glvertex(Objekt[(j*3) + 3],Objekt[(j*3) + 4],Objekt[(j*3) + 5]);
}
sketch.glend();
bang();
}

function bang(){
render.erase();
render.drawclients();
render.swap();
}

Oct 16 2012 | 2:55 pm

Did you try creating a jit.gl.light?

Oct 16 2012 | 5:42 pm

no i thought i use the light at the render, like in jitter. did i have to create a light in js?

Oct 19 2012 | 5:24 pm

You should be able to make a light anywhere, as long as its in the same context… want to post your patch?

Oct 23 2012 | 11:22 pm

Hey audiovisualist, I seem to be having some problems with gl.sketch as well.
I have been working on converting some tutorials to javascript.
http://cycling74.com/docs/max5/tutorials/jit-tut/jitterchapter40.html

In this example, only the last glcolor command shows. Which makes me think
that something is getting lost when sending commands to gl.sketch via javascript.

autowatch = 1;
inlets = 1;

var windowout = new JitterObject("jit.window","Sketchrender");
windowout.depthbuffer = 0;
windowout.idlemouse = 1;
windowout.fsaa = 1;

var render = new JitterObject("jit.gl.render","Sketchrender");
render.ortho = 1;
render.erase_color = [0,0,0,1];

function bang()
{
render.erase();
render.drawclients();
render.swap();
}

function draw()
{
drawTriangle3();
}

function drawTriangle3()
{
var sketch = new JitterObject("jit.gl.sketch","Sketchrender");
with(sketch)
{
reset();
glbegin("triangles");
glcolor(1, 0, 0, 1);
glvertex(-0.5, -0.5);
glcolor(0, 1, 0, 1);
glvertex(0, 0.5);
glcolor(0, 0, 1, 1);
glvertex(0.5, -0.5);
glend();
}
bang();
}

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

Forums > Javascript