1.在html中建立canvas 画布
<canvas id="canvas"></canvas>
2.在js中获取canvas画布
const canvas=document.getElementById('canvas’);
3.使用canvas 获取webgl 绘图上下文
const gl=canvas.getContext('webgl’);
4.指定将要用来清空绘图区的颜色
gl.clearColor(1,1,1,1);
5.使用之前指定的颜色,清空绘图区
gl.clear(gl.COLOR_BUFFER_BIT);
代码
<canvas id="canvas"></canvas>
<script>
const canvas=document.getElementById('canvas');
canvas.width=window.innerWidth;
canvas.height=window.innerHeight;
const gl=canvas.getContext('webgl');
gl.clearColor(1,1,1,1);
gl.clear(gl.COLOR_BUFFER_BIT);
</script>
clearColor(r,g,b,a) 中的参数是红、绿、蓝、透明度,其定义域是[0,1]