Web编程技术营地
研究、演示、创新

WebGLEditor Test

特性

可自动识别并读取Vertex ShaderFragment Shader标签页的内容。

attribute vec4 aPosition; void main() { gl_Position = aPosition; }
precision mediump float; void main() { gl_FragColor = vec4(0.7, 0.7, 0.0, 1.0); }
import WebGLUtils from '/tutorials/webgl/fundamentals/examples/js/esm/WebGLUtils-v2.js'; let glu, gl; let vertexVBO1, vertexVBO2; initContext(); initVBOs(); render(); function initContext() { glu = new WebGLUtils({ vertexAttribs: ['aPosition'], renderFunc: render }); gl = glu.gl; gl.clearColor(0, 0, 0, 1); } function initVBOs() { let vertices = [ 0.0, 0.5, -0.5, -0.5, 0.5, -0.5 ]; vertexVBO1 = glu.createVBO(vertices, 2); vertexVBO2 = glu.createVBO([ 0.3, 0.3, 0.6, 0.3, 0.6, 0.6 ], 2); } function render() { gl.clear(gl.COLOR_BUFFER_BIT); glu.bindVboToAttribs(vertexVBO1); gl.drawArrays(gl.TRIANGLES, 0, vertexVBO1.verticesNum); glu.bindVboToAttribs(vertexVBO2); gl.drawArrays(gl.TRIANGLES, 0, vertexVBO1.verticesNum); }
canvas { display: block; height: 450px; }

LiverEditor可自动设置输出面板高度的基础上,WebGLEditor可通过CSS面板设置canvas的高度,继而随用户意愿调节输出面板的高度。