diff --git a/Chap10/README.txt b/Chap10/README.txt old mode 100755 new mode 100644 diff --git a/Chap10/mandelbrot1.html b/Chap10/mandelbrot1.html old mode 100755 new mode 100644 diff --git a/Chap10/mandelbrot1.js b/Chap10/mandelbrot1.js old mode 100755 new mode 100644 diff --git a/Chap10/mandelbrot2.html b/Chap10/mandelbrot2.html old mode 100755 new mode 100644 diff --git a/Chap10/mandelbrot2.js b/Chap10/mandelbrot2.js old mode 100755 new mode 100644 diff --git a/Chap10/particleSystem.html b/Chap10/particleSystem.html old mode 100755 new mode 100644 diff --git a/Chap10/particleSystem.js b/Chap10/particleSystem.js old mode 100755 new mode 100644 diff --git a/Chap11/README.txt b/Chap11/README.txt old mode 100755 new mode 100644 diff --git a/Chap11/patches.js b/Chap11/patches.js old mode 100755 new mode 100644 diff --git a/Chap11/teapot1.html b/Chap11/teapot1.html old mode 100755 new mode 100644 diff --git a/Chap11/teapot1.js b/Chap11/teapot1.js old mode 100755 new mode 100644 diff --git a/Chap11/teapot2.html b/Chap11/teapot2.html old mode 100755 new mode 100644 diff --git a/Chap11/teapot2.js b/Chap11/teapot2.js old mode 100755 new mode 100644 diff --git a/Chap11/teapot3.html b/Chap11/teapot3.html old mode 100755 new mode 100644 diff --git a/Chap11/teapot3.js b/Chap11/teapot3.js old mode 100755 new mode 100644 diff --git a/Chap11/teapot4.html b/Chap11/teapot4.html old mode 100755 new mode 100644 diff --git a/Chap11/teapot4.js b/Chap11/teapot4.js old mode 100755 new mode 100644 diff --git a/Chap11/teapot5.html b/Chap11/teapot5.html old mode 100755 new mode 100644 diff --git a/Chap11/teapot5.js b/Chap11/teapot5.js old mode 100755 new mode 100644 diff --git a/Chap11/teapot6.html b/Chap11/teapot6.html old mode 100755 new mode 100644 diff --git a/Chap11/teapot7.html b/Chap11/teapot7.html old mode 100755 new mode 100644 diff --git a/Chap11/vertices.js b/Chap11/vertices.js old mode 100755 new mode 100644 diff --git a/Chap2/README.txt b/Chap2/README.txt old mode 100755 new mode 100644 diff --git a/Chap2/gasket1.html b/Chap2/gasket1.html old mode 100755 new mode 100644 diff --git a/Chap2/gasket1.js b/Chap2/gasket1.js old mode 100755 new mode 100644 diff --git a/Chap2/gasket1v2.html b/Chap2/gasket1v2.html old mode 100755 new mode 100644 diff --git a/Chap2/gasket1v2.js b/Chap2/gasket1v2.js old mode 100755 new mode 100644 diff --git a/Chap2/gasket2.html b/Chap2/gasket2.html old mode 100755 new mode 100644 diff --git a/Chap2/gasket2.js b/Chap2/gasket2.js old mode 100755 new mode 100644 diff --git a/Chap2/gasket3.html b/Chap2/gasket3.html old mode 100755 new mode 100644 diff --git a/Chap2/gasket3.js b/Chap2/gasket3.js old mode 100755 new mode 100644 diff --git a/Chap2/gasket4.html b/Chap2/gasket4.html old mode 100755 new mode 100644 diff --git a/Chap2/gasket4.js b/Chap2/gasket4.js old mode 100755 new mode 100644 diff --git a/Chap2/shaders/fshader21.glsl b/Chap2/shaders/fshader21.glsl old mode 100755 new mode 100644 diff --git a/Chap2/shaders/vshader21.glsl b/Chap2/shaders/vshader21.glsl old mode 100755 new mode 100644 diff --git a/Chap3/README.txt b/Chap3/README.txt old mode 100755 new mode 100644 diff --git a/Chap3/cad1.html b/Chap3/cad1.html old mode 100755 new mode 100644 diff --git a/Chap3/cad1.js b/Chap3/cad1.js old mode 100755 new mode 100644 diff --git a/Chap3/cad2.html b/Chap3/cad2.html old mode 100755 new mode 100644 diff --git a/Chap3/cad2.js b/Chap3/cad2.js old mode 100755 new mode 100644 diff --git a/Chap3/gasket5.html b/Chap3/gasket5.html old mode 100755 new mode 100644 diff --git a/Chap3/gasket5.js b/Chap3/gasket5.js old mode 100755 new mode 100644 diff --git a/Chap3/square.html b/Chap3/square.html old mode 100755 new mode 100644 diff --git a/Chap3/square.js b/Chap3/square.js old mode 100755 new mode 100644 diff --git a/Chap3/squarem.html b/Chap3/squarem.html old mode 100755 new mode 100644 diff --git a/Chap3/squarem.js b/Chap3/squarem.js old mode 100755 new mode 100644 diff --git a/Chap3/triangle.html b/Chap3/triangle.html old mode 100755 new mode 100644 diff --git a/Chap3/triangle.js b/Chap3/triangle.js old mode 100755 new mode 100644 diff --git a/Chap4/README.txt b/Chap4/README.txt old mode 100755 new mode 100644 diff --git a/Chap4/cube.html b/Chap4/cube.html old mode 100755 new mode 100644 diff --git a/Chap4/cube.js b/Chap4/cube.js old mode 100755 new mode 100644 diff --git a/Chap4/cubeq.html b/Chap4/cubeq.html old mode 100755 new mode 100644 diff --git a/Chap4/cubeq.js b/Chap4/cubeq.js old mode 100755 new mode 100644 diff --git a/Chap4/cubev.html b/Chap4/cubev.html old mode 100755 new mode 100644 diff --git a/Chap4/cubev.js b/Chap4/cubev.js old mode 100755 new mode 100644 diff --git a/Chap4/trackball.html b/Chap4/trackball.html old mode 100755 new mode 100644 diff --git a/Chap4/trackball.js b/Chap4/trackball.js old mode 100755 new mode 100644 diff --git a/Chap4/trackballQuaterion.html b/Chap4/trackballQuaterion.html old mode 100755 new mode 100644 diff --git a/Chap4/trackballQuaterion.js b/Chap4/trackballQuaterion.js old mode 100755 new mode 100644 diff --git a/Chap5/README.txt b/Chap5/README.txt old mode 100755 new mode 100644 diff --git a/Chap5/hat.html b/Chap5/hat.html old mode 100755 new mode 100644 diff --git a/Chap5/hat.js b/Chap5/hat.js old mode 100755 new mode 100644 diff --git a/Chap5/hata.html b/Chap5/hata.html old mode 100755 new mode 100644 diff --git a/Chap5/hata.js b/Chap5/hata.js old mode 100755 new mode 100644 diff --git a/Chap5/ortho.html b/Chap5/ortho.html old mode 100755 new mode 100644 diff --git a/Chap5/ortho.js b/Chap5/ortho.js old mode 100755 new mode 100644 diff --git a/Chap5/ortho1.html b/Chap5/ortho1.html old mode 100755 new mode 100644 diff --git a/Chap5/ortho1.js b/Chap5/ortho1.js old mode 100755 new mode 100644 diff --git a/Chap5/ortho2.html b/Chap5/ortho2.html old mode 100755 new mode 100644 diff --git a/Chap5/ortho2.js b/Chap5/ortho2.js old mode 100755 new mode 100644 diff --git a/Chap5/perspective.html b/Chap5/perspective.html old mode 100755 new mode 100644 diff --git a/Chap5/perspective.js b/Chap5/perspective.js old mode 100755 new mode 100644 diff --git a/Chap5/perspective1.html b/Chap5/perspective1.html old mode 100755 new mode 100644 diff --git a/Chap5/perspective1.js b/Chap5/perspective1.js old mode 100755 new mode 100644 diff --git a/Chap5/perspective2.html b/Chap5/perspective2.html old mode 100755 new mode 100644 diff --git a/Chap5/perspective2.js b/Chap5/perspective2.js old mode 100755 new mode 100644 diff --git a/Chap5/shadow.html b/Chap5/shadow.html old mode 100755 new mode 100644 diff --git a/Chap5/shadow.js b/Chap5/shadow.js old mode 100755 new mode 100644 diff --git a/Chap6/README.txt b/Chap6/README.txt old mode 100755 new mode 100644 diff --git a/Chap6/shadedCube.html b/Chap6/shadedCube.html old mode 100755 new mode 100644 diff --git a/Chap6/shadedCube.js b/Chap6/shadedCube.js old mode 100755 new mode 100644 diff --git a/Chap6/shadedSphere1.html b/Chap6/shadedSphere1.html old mode 100755 new mode 100644 diff --git a/Chap6/shadedSphere1.js b/Chap6/shadedSphere1.js old mode 100755 new mode 100644 diff --git a/Chap6/shadedSphere2.html b/Chap6/shadedSphere2.html old mode 100755 new mode 100644 diff --git a/Chap6/shadedSphere2.js b/Chap6/shadedSphere2.js old mode 100755 new mode 100644 diff --git a/Chap6/shadedSphere3.html b/Chap6/shadedSphere3.html old mode 100755 new mode 100644 diff --git a/Chap6/shadedSphere3.js b/Chap6/shadedSphere3.js old mode 100755 new mode 100644 diff --git a/Chap6/shadedSphere4.html b/Chap6/shadedSphere4.html old mode 100755 new mode 100644 diff --git a/Chap6/shadedSphere4.js b/Chap6/shadedSphere4.js old mode 100755 new mode 100644 diff --git a/Chap6/shadedSphereEyeSpace.html b/Chap6/shadedSphereEyeSpace.html old mode 100755 new mode 100644 diff --git a/Chap6/shadedSphereEyeSpace.js b/Chap6/shadedSphereEyeSpace.js old mode 100755 new mode 100644 diff --git a/Chap6/shadedSphereObjectSpace.html b/Chap6/shadedSphereObjectSpace.html old mode 100755 new mode 100644 diff --git a/Chap6/shadedSphereObjectSpace.js b/Chap6/shadedSphereObjectSpace.js old mode 100755 new mode 100644 diff --git a/Chap6/wireSphere.html b/Chap6/wireSphere.html old mode 100755 new mode 100644 diff --git a/Chap6/wireSphere.js b/Chap6/wireSphere.js old mode 100755 new mode 100644 diff --git a/Chap7/README.txt b/Chap7/README.txt old mode 100755 new mode 100644 diff --git a/Chap7/SA2011_black.gif b/Chap7/SA2011_black.gif old mode 100755 new mode 100644 diff --git a/Chap7/bumpMap.html b/Chap7/bumpMap.html old mode 100755 new mode 100644 diff --git a/Chap7/bumpMap.js b/Chap7/bumpMap.js old mode 100755 new mode 100644 diff --git a/Chap7/bumpMap2.html b/Chap7/bumpMap2.html old mode 100755 new mode 100644 diff --git a/Chap7/bumpMap2.js b/Chap7/bumpMap2.js old mode 100755 new mode 100644 diff --git a/Chap7/cubet.html b/Chap7/cubet.html old mode 100755 new mode 100644 diff --git a/Chap7/cubet.js b/Chap7/cubet.js old mode 100755 new mode 100644 diff --git a/Chap7/hatImage1.html b/Chap7/hatImage1.html old mode 100755 new mode 100644 diff --git a/Chap7/hatImage1.js b/Chap7/hatImage1.js old mode 100755 new mode 100644 diff --git a/Chap7/hatImage2.html b/Chap7/hatImage2.html old mode 100755 new mode 100644 diff --git a/Chap7/hatImage2.js b/Chap7/hatImage2.js old mode 100755 new mode 100644 diff --git a/Chap7/hawaiiImage.html b/Chap7/hawaiiImage.html old mode 100755 new mode 100644 diff --git a/Chap7/hawaiiImage.js b/Chap7/hawaiiImage.js old mode 100755 new mode 100644 diff --git a/Chap7/hawaiiIsobel.html b/Chap7/hawaiiIsobel.html old mode 100755 new mode 100644 diff --git a/Chap7/hawaiisobel.js b/Chap7/hawaiisobel.js old mode 100755 new mode 100644 diff --git a/Chap7/honolulu256.js b/Chap7/honolulu256.js old mode 100755 new mode 100644 diff --git a/Chap7/honolulu4.js b/Chap7/honolulu4.js old mode 100755 new mode 100644 diff --git a/Chap7/pickCube.html b/Chap7/pickCube.html old mode 100755 new mode 100644 diff --git a/Chap7/pickCube.js b/Chap7/pickCube.js old mode 100755 new mode 100644 diff --git a/Chap7/pickCube2.html b/Chap7/pickCube2.html old mode 100755 new mode 100644 diff --git a/Chap7/pickCube2.js b/Chap7/pickCube2.js old mode 100755 new mode 100644 diff --git a/Chap7/pickCube3.html b/Chap7/pickCube3.html old mode 100755 new mode 100644 diff --git a/Chap7/pickCube3.js b/Chap7/pickCube3.js old mode 100755 new mode 100644 diff --git a/Chap7/pickCube4.html b/Chap7/pickCube4.html old mode 100755 new mode 100644 diff --git a/Chap7/pickCube4.js b/Chap7/pickCube4.js old mode 100755 new mode 100644 diff --git a/Chap7/pickCube5.html b/Chap7/pickCube5.html old mode 100755 new mode 100644 diff --git a/Chap7/pickCube5.js b/Chap7/pickCube5.js old mode 100755 new mode 100644 diff --git a/Chap7/reflectiingCube.html b/Chap7/reflectiingCube.html old mode 100755 new mode 100644 diff --git a/Chap7/reflectingCube.js b/Chap7/reflectingCube.js old mode 100755 new mode 100644 diff --git a/Chap7/reflectingSphere.html b/Chap7/reflectingSphere.html old mode 100755 new mode 100644 diff --git a/Chap7/reflectingSphere.js b/Chap7/reflectingSphere.js old mode 100755 new mode 100644 diff --git a/Chap7/reflectionMap.html b/Chap7/reflectionMap.html old mode 100755 new mode 100644 diff --git a/Chap7/reflectionMap.js b/Chap7/reflectionMap.js old mode 100755 new mode 100644 diff --git a/Chap7/reflectionMap2.html b/Chap7/reflectionMap2.html old mode 100755 new mode 100644 diff --git a/Chap7/reflectionMap2.js b/Chap7/reflectionMap2.js old mode 100755 new mode 100644 diff --git a/Chap7/render1.html b/Chap7/render1.html old mode 100755 new mode 100644 diff --git a/Chap7/render1.js b/Chap7/render1.js old mode 100755 new mode 100644 diff --git a/Chap7/render1v2.html b/Chap7/render1v2.html old mode 100755 new mode 100644 diff --git a/Chap7/render1v2.js b/Chap7/render1v2.js old mode 100755 new mode 100644 diff --git a/Chap7/render3.html b/Chap7/render3.html old mode 100755 new mode 100644 diff --git a/Chap7/render3.js b/Chap7/render3.js old mode 100755 new mode 100644 diff --git a/Chap7/render4.html b/Chap7/render4.html old mode 100755 new mode 100644 diff --git a/Chap7/render4.js b/Chap7/render4.js old mode 100755 new mode 100644 diff --git a/Chap7/render5.html b/Chap7/render5.html old mode 100755 new mode 100644 diff --git a/Chap7/render5.js b/Chap7/render5.js old mode 100755 new mode 100644 diff --git a/Chap7/textureCube1.html b/Chap7/textureCube1.html old mode 100755 new mode 100644 diff --git a/Chap7/textureCube1.js b/Chap7/textureCube1.js old mode 100755 new mode 100644 diff --git a/Chap7/textureCubev2.html b/Chap7/textureCubev2.html old mode 100755 new mode 100644 diff --git a/Chap7/textureCubev2.js b/Chap7/textureCubev2.js old mode 100755 new mode 100644 diff --git a/Chap7/textureCubev3.html b/Chap7/textureCubev3.html old mode 100755 new mode 100644 diff --git a/Chap7/textureCubev3.js b/Chap7/textureCubev3.js old mode 100755 new mode 100644 diff --git a/Chap7/textureCubev4.html b/Chap7/textureCubev4.html old mode 100755 new mode 100644 diff --git a/Chap7/textureCubev4.js b/Chap7/textureCubev4.js old mode 100755 new mode 100644 diff --git a/Chap7/textureSquare.html b/Chap7/textureSquare.html old mode 100755 new mode 100644 diff --git a/Chap7/textureSquare.js b/Chap7/textureSquare.js old mode 100755 new mode 100644 diff --git a/Chap9/README.txt b/Chap9/README.txt old mode 100755 new mode 100644 diff --git a/Chap9/figure.html b/Chap9/figure.html old mode 100755 new mode 100644 diff --git a/Chap9/figure.js b/Chap9/figure.js old mode 100755 new mode 100644 diff --git a/Chap9/robotArm.html b/Chap9/robotArm.html old mode 100755 new mode 100644 diff --git a/Chap9/robotArm.js b/Chap9/robotArm.js old mode 100755 new mode 100644 diff --git a/Common/MV.js b/Common/MV.js old mode 100755 new mode 100644 index 16f3f37..e9e6a84 --- a/Common/MV.js +++ b/Common/MV.js @@ -164,10 +164,12 @@ function mat4() function equal( u, v ) { + var i; + if ( u.length != v.length ) { return false; } if ( u.matrix && v.matrix ) { - for ( var i = 0; i < u.length; ++i ) { + for ( i = 0; i < u.length; ++i ) { if ( u[i].length != v[i].length ) { return false; } for ( var j = 0; j < u[i].length; ++j ) { if ( u[i][j] !== v[i][j] ) { return false; } @@ -177,10 +179,9 @@ function equal( u, v ) else if ( u.matrix && !v.matrix || !u.matrix && v.matrix ) { return false; } - else { - for ( var i = 0; i < u.length; ++i ) { - if ( u[i] !== v[i] ) { return false; } - } + + for ( i = 0; i < u.length; ++i ) { + if ( u[i] !== v[i] ) { return false; } } return true; @@ -191,13 +192,14 @@ function equal( u, v ) function add( u, v ) { var result = []; + var i; if ( u.matrix && v.matrix ) { if ( u.length != v.length ) { throw "add(): trying to add matrices of different dimensions"; } - for ( var i = 0; i < u.length; ++i ) { + for ( i = 0; i < u.length; ++i ) { if ( u[i].length != v[i].length ) { throw "add(): trying to add matrices of different dimensions"; } @@ -214,17 +216,16 @@ function add( u, v ) else if ( u.matrix && !v.matrix || !u.matrix && v.matrix ) { throw "add(): trying to add matrix and non-matrix variables"; } - else { - if ( u.length != v.length ) { - throw "add(): vectors are not the same dimension"; - } - for ( var i = 0; i < u.length; ++i ) { - result.push( u[i] + v[i] ); - } + if ( u.length != v.length ) { + throw "add(): vectors are not the same dimension"; + } - return result; + for ( i = 0; i < u.length; ++i ) { + result.push( u[i] + v[i] ); } + + return result; } //---------------------------------------------------------------------------- @@ -232,6 +233,7 @@ function add( u, v ) function subtract( u, v ) { var result = []; + var i; if ( u.matrix && v.matrix ) { if ( u.length != v.length ) { @@ -239,9 +241,9 @@ function subtract( u, v ) " of different dimensions"; } - for ( var i = 0; i < u.length; ++i ) { + for ( i = 0; i < u.length; ++i ) { if ( u[i].length != v[i].length ) { - throw "subtract(): trying to subtact matrices" + + throw "subtract(): trying to subtract matrices" + " of different dimensions"; } result.push( [] ); @@ -255,19 +257,18 @@ function subtract( u, v ) return result; } else if ( u.matrix && !v.matrix || !u.matrix && v.matrix ) { - throw "subtact(): trying to subtact matrix and non-matrix variables"; + throw "subtract(): trying to subtract matrix and non-matrix variables"; } - else { - if ( u.length != v.length ) { - throw "subtract(): vectors are not the same length"; - } - for ( var i = 0; i < u.length; ++i ) { - result.push( u[i] - v[i] ); - } + if ( u.length != v.length ) { + throw "subtract(): vectors are not the same length"; + } - return result; + for ( i = 0; i < u.length; ++i ) { + result.push( u[i] - v[i] ); } + + return result; } //---------------------------------------------------------------------------- @@ -275,19 +276,20 @@ function subtract( u, v ) function mult( u, v ) { var result = []; + var i; if ( u.matrix && v.matrix ) { if ( u.length != v.length ) { - throw "mult(): trying to add matrices of different dimensions"; + throw "mult(): trying to multiply matrices of different dimensions"; } - for ( var i = 0; i < u.length; ++i ) { + for ( i = 0; i < u.length; ++i ) { if ( u[i].length != v[i].length ) { - throw "mult(): trying to add matrices of different dimensions"; + throw "mult(): trying to multiply matrices of different dimensions"; } } - for ( var i = 0; i < u.length; ++i ) { + for ( i = 0; i < u.length; ++i ) { result.push( [] ); for ( var j = 0; j < v.length; ++j ) { @@ -303,17 +305,16 @@ function mult( u, v ) return result; } - else { - if ( u.length != v.length ) { - throw "mult(): vectors are not the same dimension"; - } - for ( var i = 0; i < u.length; ++i ) { - result.push( u[i] * v[i] ); - } + if ( u.length != v.length ) { + throw "mult(): vectors are not the same dimension"; + } - return result; + for ( i = 0; i < u.length; ++i ) { + result.push( u[i] * v[i] ); } + + return result; } //---------------------------------------------------------------------------- @@ -391,15 +392,15 @@ function scalem( x, y, z ) function lookAt( eye, at, up ) { if ( !Array.isArray(eye) || eye.length != 3) { - throw "lookAt(): first parameter [eye] must be an a vec3"; + throw "lookAt(): first parameter [eye] must be a vec3"; } if ( !Array.isArray(at) || at.length != 3) { - throw "lookAt(): first parameter [at] must be an a vec3"; + throw "lookAt(): second parameter [at] must be a vec3"; } if ( !Array.isArray(up) || up.length != 3) { - throw "lookAt(): first parameter [up] must be an a vec3"; + throw "lookAt(): third parameter [up] must be a vec3"; } if ( equal(eye, at) ) { @@ -526,11 +527,11 @@ function negate( u ) function cross( u, v ) { if ( !Array.isArray(u) || u.length < 3 ) { - throw "cross(): first argument is not a vector of at least 3"; + throw "cross(): first argument is not a vector of dimension at least 3"; } if ( !Array.isArray(v) || v.length < 3 ) { - throw "cross(): second argument is not a vector of at least 3"; + throw "cross(): second argument is not a vector of dimension at least 3"; } var result = [ @@ -579,7 +580,7 @@ function normalize( u, excludeLastComponent ) function mix( u, v, s ) { if ( typeof s !== "number" ) { - throw "mix: the last paramter " + s + " must be a number"; + throw "mix: the last parameter " + s + " must be a number"; } if ( u.length != v.length ) { @@ -634,16 +635,18 @@ function flatten( v ) var floats = new Float32Array( n ); + var i; + if ( elemsAreArrays ) { var idx = 0; - for ( var i = 0; i < v.length; ++i ) { + for ( i = 0; i < v.length; ++i ) { for ( var j = 0; j < v[i].length; ++j ) { floats[idx++] = v[i][j]; } } } else { - for ( var i = 0; i < v.length; ++i ) { + for ( i = 0; i < v.length; ++i ) { floats[i] = v[i]; } } @@ -668,70 +671,72 @@ var sizeof = { function printm(m) { + var i; + if(m.length == 2) - for(var i=0; i" + gl.getShaderInfoLog( vertShdr ) + ""; - alert( msg ); - return -1; - } + + vertShdr = gl.createShader( gl.VERTEX_SHADER ); + gl.shaderSource( vertShdr, vertElem.text ); + gl.compileShader( vertShdr ); + if ( !gl.getShaderParameter(vertShdr, gl.COMPILE_STATUS) ) { + msg = "Vertex shader failed to compile. The error log is:" + + "
" + gl.getShaderInfoLog( vertShdr ) + "
"; + alert( msg ); + return -1; } var fragElem = document.getElementById( fragmentShaderId ); - if ( !fragElem ) { + if ( !fragElem ) { alert( "Unable to load vertex shader " + fragmentShaderId ); return -1; } - else { - fragShdr = gl.createShader( gl.FRAGMENT_SHADER ); - gl.shaderSource( fragShdr, fragElem.text ); - gl.compileShader( fragShdr ); - if ( !gl.getShaderParameter(fragShdr, gl.COMPILE_STATUS) ) { - var msg = "Fragment shader failed to compile. The error log is:" - + "
" + gl.getShaderInfoLog( fragShdr ) + "
"; - alert( msg ); - return -1; - } + + fragShdr = gl.createShader( gl.FRAGMENT_SHADER ); + gl.shaderSource( fragShdr, fragElem.text ); + gl.compileShader( fragShdr ); + if ( !gl.getShaderParameter(fragShdr, gl.COMPILE_STATUS) ) { + msg = "Fragment shader failed to compile. The error log is:" + + "
" + gl.getShaderInfoLog( fragShdr ) + "
"; + alert( msg ); + return -1; } var program = gl.createProgram(); gl.attachShader( program, vertShdr ); gl.attachShader( program, fragShdr ); gl.linkProgram( program ); - + if ( !gl.getProgramParameter(program, gl.LINK_STATUS) ) { - var msg = "Shader program failed to link. The error log is:" + msg = "Shader program failed to link. The error log is:" + "
" + gl.getProgramInfoLog( program ) + "
"; alert( msg ); return -1; diff --git a/Common/initShaders2.js b/Common/initShaders2.js old mode 100755 new mode 100644 index 49b5933..f90a0b0 --- a/Common/initShaders2.js +++ b/Common/initShaders2.js @@ -1,44 +1,42 @@ +// Get a file as a string using AJAX +function loadFileAJAX(name) { + var xhr = new XMLHttpRequest(), + okStatus = document.location.protocol === "file:" ? 0 : 200; + xhr.open('GET', name, false); + xhr.send(null); + return xhr.status == okStatus ? xhr.responseText : null; +}; - // Get a file as a string using AJAX - function loadFileAJAX(name) { - var xhr = new XMLHttpRequest(), - okStatus = document.location.protocol === "file:" ? 0 : 200; - xhr.open('GET', name, false); - xhr.send(null); - return xhr.status == okStatus ? xhr.responseText : null; - }; - - function initShaders(gl, vShaderName, fShaderName) { - function getShader(gl, shaderName, type) { - var shader = gl.createShader(type), - shaderScript = loadFileAJAX(shaderName); - if (!shaderScript) { - alert("Could not find shader source: "+shaderName); - } - gl.shaderSource(shader, shaderScript); - gl.compileShader(shader); - - if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { - alert(gl.getShaderInfoLog(shader)); - return null; - } - return shader; +function initShaders(gl, vShaderName, fShaderName) { + function getShader(gl, shaderName, type) { + var shader = gl.createShader(type), + shaderScript = loadFileAJAX(shaderName); + if (!shaderScript) { + alert("Could not find shader source: "+shaderName); } - var vertexShader = getShader(gl, vShaderName, gl.VERTEX_SHADER), - fragmentShader = getShader(gl, fShaderName, gl.FRAGMENT_SHADER), - program = gl.createProgram(); - - gl.attachShader(program, vertexShader); - gl.attachShader(program, fragmentShader); - gl.linkProgram(program); + gl.shaderSource(shader, shaderScript); + gl.compileShader(shader); - if (!gl.getProgramParameter(program, gl.LINK_STATUS)) { - alert("Could not initialise shaders"); + if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { + alert(gl.getShaderInfoLog(shader)); return null; } + return shader; + } + var vertexShader = getShader(gl, vShaderName, gl.VERTEX_SHADER), + fragmentShader = getShader(gl, fShaderName, gl.FRAGMENT_SHADER), + program = gl.createProgram(); + + gl.attachShader(program, vertexShader); + gl.attachShader(program, fragmentShader); + gl.linkProgram(program); + + if (!gl.getProgramParameter(program, gl.LINK_STATUS)) { + alert("Could not initialise shaders"); + return null; + } - - return program; - }; + return program; +}; diff --git a/Common/webgl-utils.js b/Common/webgl-utils.js old mode 100755 new mode 100644 index c2b2918..4852b4c --- a/Common/webgl-utils.js +++ b/Common/webgl-utils.js @@ -1,164 +1,162 @@ -/* - * Copyright 2010, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -/** - * @fileoverview This file contains functions every webgl program will need - * a version of one way or another. - * - * Instead of setting up a context manually it is recommended to - * use. This will check for success or failure. On failure it - * will attempt to present an approriate message to the user. - * - * gl = WebGLUtils.setupWebGL(canvas); - * - * For animated WebGL apps use of setTimeout or setInterval are - * discouraged. It is recommended you structure your rendering - * loop like this. - * - * function render() { - * window.requestAnimFrame(render, canvas); - * - * // do rendering - * ... - * } - * render(); - * - * This will call your rendering function up to the refresh rate - * of your display but will stop rendering if your app is not - * visible. - */ - -WebGLUtils = function() { - -/** - * Creates the HTLM for a failure message - * @param {string} canvasContainerId id of container of th - * canvas. - * @return {string} The html. - */ -var makeFailHTML = function(msg) { - return '' + - '' + - '
' + - '
' + - '
' + msg + '
' + - '
' + - '
'; -}; - -/** - * Mesasge for getting a webgl browser - * @type {string} - */ -var GET_A_WEBGL_BROWSER = '' + - 'This page requires a browser that supports WebGL.
' + - 'Click here to upgrade your browser.'; - -/** - * Mesasge for need better hardware - * @type {string} - */ -var OTHER_PROBLEM = '' + - "It doesn't appear your computer can support WebGL.
" + - 'Click here for more information.'; - -/** - * Creates a webgl context. If creation fails it will - * change the contents of the container of the - * tag to an error message with the correct links for WebGL. - * @param {Element} canvas. The canvas element to create a - * context from. - * @param {WebGLContextCreationAttirbutes} opt_attribs Any - * creation attributes you want to pass in. - * @return {WebGLRenderingContext} The created context. - */ -var setupWebGL = function(canvas, opt_attribs) { - function showLink(str) { - var container = canvas.parentNode; - if (container) { - container.innerHTML = makeFailHTML(str); - } - }; - - if (!window.WebGLRenderingContext) { - showLink(GET_A_WEBGL_BROWSER); - return null; - } - - var context = create3DContext(canvas, opt_attribs); - if (!context) { - showLink(OTHER_PROBLEM); - } - return context; -}; - -/** - * Creates a webgl context. - * @param {!Canvas} canvas The canvas tag to get context - * from. If one is not passed in one will be created. - * @return {!WebGLContext} The created context. - */ -var create3DContext = function(canvas, opt_attribs) { - var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"]; - var context = null; - for (var ii = 0; ii < names.length; ++ii) { - try { - context = canvas.getContext(names[ii], opt_attribs); - } catch(e) {} - if (context) { - break; - } - } - return context; -} - -return { - create3DContext: create3DContext, - setupWebGL: setupWebGL -}; -}(); - -/** - * Provides requestAnimationFrame in a cross browser way. - */ -window.requestAnimFrame = (function() { - return window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame || - window.msRequestAnimationFrame || - function(/* function FrameRequestCallback */ callback, /* DOMElement Element */ element) { - window.setTimeout(callback, 1000/60); - }; -})(); - - +/* + * Copyright 2010, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +/** + * @fileoverview This file contains functions every webgl program will need + * a version of one way or another. + * + * Instead of setting up a context manually it is recommended to + * use. This will check for success or failure. On failure it + * will attempt to present an approriate message to the user. + * + * gl = WebGLUtils.setupWebGL(canvas); + * + * For animated WebGL apps use of setTimeout or setInterval are + * discouraged. It is recommended you structure your rendering + * loop like this. + * + * function render() { + * window.requestAnimFrame(render, canvas); + * + * // do rendering + * ... + * } + * render(); + * + * This will call your rendering function up to the refresh rate + * of your display but will stop rendering if your app is not + * visible. + */ + +WebGLUtils = function() { + + /** + * Creates the HTLM for a failure message + * @param {string} canvasContainerId id of container of th + * canvas. + * @return {string} The html. + */ + var makeFailHTML = function(msg) { + return '' + + '' + + '
' + + '
' + + '
' + msg + '
' + + '
' + + '
'; + }; + + /** + * Mesasge for getting a webgl browser + * @type {string} + */ + var GET_A_WEBGL_BROWSER = '' + + 'This page requires a browser that supports WebGL.
' + + 'Click here to upgrade your browser.'; + + /** + * Mesasge for need better hardware + * @type {string} + */ + var OTHER_PROBLEM = '' + + "It doesn't appear your computer can support WebGL.
" + + 'Click here for more information.'; + + /** + * Creates a webgl context. If creation fails it will + * change the contents of the container of the + * tag to an error message with the correct links for WebGL. + * @param {Element} canvas. The canvas element to create a + * context from. + * @param {WebGLContextCreationAttirbutes} opt_attribs Any + * creation attributes you want to pass in. + * @return {WebGLRenderingContext} The created context. + */ + var setupWebGL = function(canvas, opt_attribs) { + function showLink(str) { + var container = canvas.parentNode; + if (container) { + container.innerHTML = makeFailHTML(str); + } + }; + + if (!window.WebGLRenderingContext) { + showLink(GET_A_WEBGL_BROWSER); + return null; + } + + var context = create3DContext(canvas, opt_attribs); + if (!context) { + showLink(OTHER_PROBLEM); + } + return context; + }; + + /** + * Creates a webgl context. + * @param {!Canvas} canvas The canvas tag to get context + * from. If one is not passed in one will be created. + * @return {!WebGLContext} The created context. + */ + var create3DContext = function(canvas, opt_attribs) { + var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"]; + var context = null; + for (var ii = 0; ii < names.length; ++ii) { + try { + context = canvas.getContext(names[ii], opt_attribs); + } catch(e) {} + if (context) { + break; + } + } + return context; + }; + + return { + create3DContext: create3DContext, + setupWebGL: setupWebGL + }; +}(); + +/** + * Provides requestAnimationFrame in a cross browser way. + */ +window.requestAnimFrame = (function() { + return window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function(/* function FrameRequestCallback */ callback, /* DOMElement Element */ element) { + window.setTimeout(callback, 1000/60); + }; +})();