Ignore:
Timestamp:
12/07/15 23:23:47 (9 years ago)
Author:
dlcheng
Message:

ADD: javascript: plot_overlay functionality.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/plot/webgl.js

    r19853 r19864  
    2222        // Clear the color as well as the depth buffer.
    2323        gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     24        // Enable color blending/overlay
     25        gl.enable(gl.BLEND);
    2426
    2527        // Allocate arrays equal to maximium number of attributes used by any one shader
     
    99101} //}}}
    100102function Node(gl,options) { //{{{
    101        
    102         var node;
    103 
    104         node= {buffers:[],
     103        //Returns a Node object that contains default display states for webgl object
     104        return {buffers:[],
    105105                shader:gl.shaders["unlit_textured"]["program"],
    106106                draw:null,
     
    109109                useIndexBuffer:true,
    110110                useOrthographic:false,
    111                 transparency:1.0,
     111                alpha:1.0,
    112112                disableDepthTest:false,
    113113                enableCullFace:false,
     
    120120                modelMatrix:mat4.create(),
    121121                shaderName:"unlit_textured",
     122                overlay:false,
    122123        };
    123        
    124         return node;
    125 
    126124} //}}}
    127125function recalculateModelMatrix(node) { //{{{
     
    210208                '',
    211209                'uniform sampler2D uColorSampler;',
     210                'uniform float uAlpha;',
    212211                '',
    213212                'void main(void) {',
    214                 '       gl_FragColor = texture2D(uColorSampler, vec2(vTextureCoord.s, vTextureCoord.t));',
     213                '       gl_FragColor = vec4(texture2D(uColorSampler, vec2(vTextureCoord.s, vTextureCoord.t)).rgb, uAlpha);',
    215214                '}'].join('\n');
    216215        shaderNames.forEach(function(shaderName){
     
    323322        }
    324323        gl.uniformMatrix4fv(node["shader"]["uMVPMatrix"], false, mvpMatrix);
    325         gl.uniform1f(node["shader"]["uAlpha"], node["transparency"]);
     324        gl.uniform1f(node["shader"]["uAlpha"], node["alpha"]);
    326325        if (node["texture"]) {
    327326                gl.activeTexture(gl.TEXTURE0);
     
    329328                gl.uniform1i(node["shader"]["uColorSampler"], 0);       
    330329        }
    331         if  (node["useIndexBuffer"]) {
     330        if (node["overlay"] == true) {
     331                gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
     332        }
     333        else {
     334                gl.blendFunc (gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
     335        }
     336        if  (node["useIndexBuffer"] == true) {
    332337                gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, node["buffers"][node["buffers"].length - 1]);
    333338                gl.drawElements(node["drawMode"], node["buffers"][node["buffers"].length - 1].numItems, gl.UNSIGNED_SHORT, 0);
     
    350355        }
    351356} //}}}
    352 function draw(gl,options,canvas,node) { //{{{
     357function draw(gl,options,canvas,nodes) { //{{{
    353358
    354359        // Set clear color to black, fully opaque
     
    358363        }
    359364        else throw Error(sprintf("s%s%s\n","initWebGL error message: cound not find out background color for curent canvas ",canvas));
    360        
     365               
    361366        // Clear the color as well as the depth buffer.
    362367        gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    363368
    364         window.requestAnimationFrame(function(time) {draw(gl,options,canvas,node)});
     369        window.requestAnimationFrame(function(time) {draw(gl,options,canvas,nodes)});
    365370        updateCameraMatrix(canvas);
    366 
    367         drawSceneGraphNode(gl, canvas, node);
     371        for (var node in nodes) {
     372                drawSceneGraphNode(gl, canvas, nodes[node]);
     373        }
    368374} //}}}
    369375//}}}
Note: See TracChangeset for help on using the changeset viewer.