WebGL 帮助类库:TWGL
n6xb
10年前
这个JS库的唯一目的就是让使用WebGL的API更简洁。
<canvas id="c"></canvas> <script src="../dist/twgl-full.min.js"></script> <script> var gl = twgl.getWebGLContext(document.getElementById("c")); var programInfo = twgl.createProgramInfo(gl, ["vs", "fs"]); var arrays = { position: [-1, -1, 0, 1, -1, 0, -1, 1, 0, -1, 1, 0, 1, -1, 0, 1, 1, 0], }; var bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays); var start = Date.now() * 0.001; function render() { twgl.resizeCanvasToDisplaySize(gl.canvas); gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); var uniforms = { time: Date.now() * 0.001 - start, resolution: [gl.canvas.width, gl.canvas.height], }; gl.useProgram(programInfo.program); twgl.setBuffersAndAttributes(gl, programInfo, bufferInfo); twgl.setUniforms(programInfo, uniforms); twgl.drawBufferInfo(gl, gl.TRIANGLES, bufferInfo); requestAnimationFrame(render); } render(); </script>