Problem with bgcolor in a jsui


    Jun 05 2006 | 3:13 pm
    Hi,
    I have a problem with bgcolor in a jsui. I want to draw a 3d aspect sphere in a jsui fader. In order to have best result, i don't redraw the background each time i move the fader. I first draw the bg in a sketch called "myskechbg" and when i update the jsui, i just redraw it using the copypixels method.
    This work great except a little problem :
    I draw a plane in the bg and if the color of this plane is choosen by arguments in the jsui, it work, but if i send the message rgb2 to my jsui and then redraw the bg and then redraw the fader, the plane in the background dissappears.
    Can someone help me? I am quite sure i made a mistake in my 3D code, but as i am not really experimented with open gl, i can't find it.
    I wonder if my explications are clear enough...
    The code is below. Thanks. Philippe OLLIVIER.
    /*
    */ inlets=2; outlets=3; autowatch=1; sketch.ortho3d(); var val = 0; var vbrgb = [1.,1.,1.]; var vfrgb = [0.7,0.2,0.2]; var vrgb2 = [0.5,0.5,0.5]; var vmode = 0; var voutline = 1; var width = box.rect[2] - box.rect[0]; var height = box.rect[3] - box.rect[1]; var aspect = width/height; var mysketchbg=new Sketch(width,height) mysketchbg.ortho3d();
    // process arguments if (jsarguments.length>1) vfrgb[0] = jsarguments[1]/255.; if (jsarguments.length>2) vfrgb[1] = jsarguments[2]/255.; if (jsarguments.length>3) vfrgb[2] = jsarguments[3]/255.; if (jsarguments.length>4) vbrgb[0] = jsarguments[4]/255.; if (jsarguments.length>5) vbrgb[1] = jsarguments[5]/255.; if (jsarguments.length>6) vbrgb[2] = jsarguments[6]/255.; if (jsarguments.length>7) vrgb2[0] = jsarguments[7]/255.; if (jsarguments.length>8) vrgb2[1] = jsarguments[8]/255.; if (jsarguments.length>9) vrgb2[2] = jsarguments[9]/255.; if (jsarguments.length>10) vmode = jsarguments[10]; if (jsarguments.length>11) voutline = jsarguments[11];
    draw_bg() draw(); refresh();
    function draw_bg() {
    with (mysketchbg) {
    //scale everything to box size glmatrixmode("modelview"); glpushmatrix(); glscale(aspect,1,1); glenable("line_smooth");
    // erase background glclearcolor(vbrgb); glclear();
    sketch.shapeorient(0,0,0) glcolor(vrgb2); shapeslice(1,1); moveto(0,0); plane(0.1,0.8);
    } }
    function draw() {
    with (sketch) {
    // erase background glclearcolor(vbrgb); glclear();
    //draw line copypixels(mysketchbg,0,0);
    // draw marker glcolor(vfrgb); moveto(0.,1.6*val-0.8); //on screen in range -0.8 to 0.8 sketch.sphere(aspect*.5)
    } } function frgb(r,g,b) { vfrgb[0] = r/255.; vfrgb[1] = g/255.; vfrgb[2] = b/255.; draw(); refresh(); }
    function rgb2(r,g,b) { vrgb2[0] = r/255.; vrgb2[1] = g/255.; vrgb2[2] = b/255.; draw_bg(); draw(); refresh(); }
    function brgb(r,g,b) { vbrgb[0] = r/255.; vbrgb[1] = g/255.; vbrgb[2] = b/255.; draw_bg(); draw(); refresh(); }
    function mode(v) { vmode = v; draw(); refresh(); }
    function outline(v) { voutline = v; draw(); refresh(); }

    • Jun 05 2006 | 7:25 pm
      On Jun 5, 2006, at 8:15 AM, Philippe OLLIVIER wrote:
      > I draw a plane in the bg and if the color of this plane is choosen > by arguments in the jsui, it work, but if i send the message rgb2 > to my jsui and then redraw the bg and then redraw the fader, the > plane in the background disappears.
      In the following function, you need to pop the modelview transformation stack. i.e. after the plane() call, you need to call
      glmatrixmode("modelview"); glpopmatrix();
      Otherwise you are scaling over and over again. With this change, the rgb2 message seems to work fine for me.
      -Joshua
    • Jun 05 2006 | 7:35 pm
      Thanks Joshua,
      Work fine also for me now. Philippe.