// // initWebGL // // Initialize the Canvas element with the passed name as a WebGL object and return the // WebGLRenderingContext. // // Load shaders with the passed names and create a program with them. Return this program // in the 'program' property of the returned context. // // For each string in the passed attribs array, bind an attrib with that name at that index. // Once the attribs are bound, link the program and then use it. // // Set the clear color to the passed array (4 values) and set the clear depth to the passed value. // Enable depth testing and blending with a blend func of (SRC_ALPHA, ONE_MINUS_SRC_ALPHA) // function initWebGL(canvasName, vshader, fshader, attribs, clearColor, clearDepth) { var canvas = document.getElementById(canvasName); var gl = canvas.getContext("webkit-3d"); // create our shaders var vertexShader = loadShader(gl, vshader); var fragmentShader = loadShader(gl, fshader); if (!vertexShader || !fragmentShader) return null; // Create the program object gl.program = gl.createProgram(); if (!gl.program) return null; // Attach our two shaders to the program gl.attachShader (gl.program, vertexShader); gl.attachShader (gl.program, fragmentShader); // Bind attributes for (var i in attribs) gl.bindAttribLocation (gl.program, i, attribs[i]); // Link the program gl.linkProgram(gl.program); // Check the link status var linked = gl.getProgramParameter(gl.program, gl.LINK_STATUS); if (!linked) { // something went wrong with the link var error = gl.getProgramInfoLog (gl.program); console.log("Error in program linking:"+error); gl.deleteProgram(gl.program); gl.deleteProgram(fragmentShader); gl.deleteProgram(vertexShader); return null; } gl.useProgram(gl.program); gl.clearColor (clearColor[0], clearColor[1], clearColor[2], clearColor[3]); gl.clearDepth (clearDepth); gl.enable(gl.DEPTH_TEST); gl.enable(gl.BLEND); gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); return gl; } // // loadShader // // 'shaderId' is the id of a