gl.clearColor(0.0, 0.0, 0.0, 1.0) gl.clear(gl.COLOR_BUFFER_BIT) var vertices = [ -0.5, -0.5, 0.5, -0.5, 0, 0.5 ] var vertexBuf = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuf) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW) var program = gl.createProgram() var vs = gl.createShader(gl.VERTEX_SHADER) gl.shaderSource(vs, document.getElementById('vs').textContent) gl.compileShader(vs) gl.attachShader(program, vs) var fs = gl.createShader(gl.FRAGMENT_SHADER) gl.shaderSource(fs, document.getElementById('fs').textContent) gl.compileShader(fs) gl.attachShader(program, fs) gl.linkProgram(program) gl.useProgram(program) var vertexPosAttrib = gl.getAttribLocation(program, 'avPos') gl.enableVertexAttribArray(vertexPosAttrib) gl.vertexAttribPointer(vertexPosAttrib, 2, gl.FLOAT, false, 0, 0) //render loop requestAnimationFrame(function render() { gl.drawArrays(gl.TRIANGLES, 0, 3) requestAnimationFrame(render) })