I have this code segment:
function setupWebGL() { gl.clearColor(0.1, 0.5, 0.1, 1.0); gl.clear(gl.COLOR_BUFFER_BIT); gl.viewport(0,0,400,300); mat4.perspective(45, 400 / 300, 0.1, 100.0, pMatrix); mat4.identity(mvMatrix); mat4.translate(mvMatrix, [0, 0, -2.0]); }
And everything in the code works, except for the very last line
mat4.translate(mvMatrix, [0, 0, -2.0]);
I know this because I put warning functions after each line until they could execute (I need a better way to debug in chrome, any suggestions?)
I am using the gl-Matrix library found here https://github.com/toji/gl-matrix/blob/master/dist/gl-matrix-min.js
Any ideas on why this line stops code execution?
Here is the complete code:
<!doctype html> <html> <head> <title>WebGL - Chapter One - Lol</title> <style> body{ background-color: grey; } canvas{ background-color: white; } </style> <script src = "gl-matrix-min.js"></script> <script src = "raf_polyfill.js"></script> <script id="shader-vs" type="x-shader/x-vertex"> attribute vec3 aVertexPosition; attribute vec3 aVertexColor; uniform mat4 uMVMatrix; uniform mat4 uPMatrix; varying highp vec4 vColor; void main(void){ gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); vColor = vec4(aVertexColor, 1.0); } </script> <script id="shader-fs" type="x-shader/x-fragment"> varying highp vec4 vColor; void main(void){ gl_FragColor = vColor; } </script> <script> var gl = null, canvas = null, glProgram = null, fragmentShader = null, vertexShader = null; var vertexPositionAttribute = null, trianglesVerticeBuffer = null, vertexColorAttribute = null, trianglesColorBuffer = null; var angle = 0.0; var mvMatrix = mat4.create(), pMatrix = mat4.create(); function initWebGL(){ var canvas = document.getElementById("my-canvas"); try{ gl = canvas.getContext("experimental-webgl"); }catch(e){} if(gl){ initShaders(); setupBuffers(); getMatrixUniforms(); animLoop(); }else{ alert("Error: Your browser does not appear to support WebGL."); } } function animLoop(){ setupWebGL(); setupDynamicBuffers(); setMatrixUniforms(); drawScene(); requestAnimationFrame(animLoop,canvas); } function setupWebGL() { </script> </head> <body onload="initWebGL()"> <canvas id="my-canvas" width="400" height="300"> Your browser does not support the HTML5 canvas element. </canvas> </body> </html>