main(); function main() { const canvas = document.querySelector('#glcanvas'); const gl = canvas.getContext('webgl'); if (!gl) { alert('Unable to initialize WebGL. Your browser or machine may not support it.'); return; } const shaderProgramFactory = new ShaderProgramFactory(gl); const shaderProgram = shaderProgramFactory.createShaderProgram(); // Collect all the info needed to use the shader program. // Look up which attributes our shader program is using // for aVertexPosition, aVertexNormal, aTextureCoord, // and look up uniform locations. const programInfo = { program: shaderProgram, attribLocations: { vertexPosition: gl.getAttribLocation(shaderProgram, 'aVertexPosition'), vertexNormal: gl.getAttribLocation(shaderProgram, 'aVertexNormal'), textureCoord: gl.getAttribLocation(shaderProgram, 'aTextureCoord'), }, uniformLocations: { projectionMatrix: gl.getUniformLocation(shaderProgram, 'uProjectionMatrix'), modelViewMatrix: gl.getUniformLocation(shaderProgram, 'uModelViewMatrix'), normalMatrix: gl.getUniformLocation(shaderProgram, 'uNormalMatrix'), uSampler: gl.getUniformLocation(shaderProgram, 'uSampler'), }, }; const cubeBuffer = new CubeBuffer(gl); const buffers = cubeBuffer.startBuffer(); const imageLoader = new ImageLoader(gl); const texture = imageLoader.loadImageIntoTexture( 'cubetexture.png'); var then = 0; // Draw the scene repeatedly function render(now) { now *= 0.001; // convert to seconds const deltaTime = now - then; then = now; drawScene(gl, programInfo, buffers, texture, deltaTime); requestAnimationFrame(render); } requestAnimationFrame(render); }