美文网首页
webgl 2.清屏

webgl 2.清屏

作者: lesliefang | 来源:发表于2017-08-24 17:13 被阅读104次

所有 code 已在 Chrome 最新版中测试通过
源码请查看 https://github.com/lesliebeijing/webgl-tutorial
代码基于 WebGL1.0 即 OpenGL ES 2.0

clear.png
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>clear</title>
</head>
<body>

<canvas id="canvas" width="400" height="400">
    Please use a browser that supports "canvas"
</canvas>

<script>
    var canvas = document.getElementById("canvas");
    var gl = canvas.getContext('webgl');

    gl.clearColor(0.0, 0.0, 0.0, 1.0);
    gl.clear(gl.COLOR_BUFFER_BIT);

</script>
</body>
</html>

webgl 也是绘制在 canvas 中的

  • canvas.getContext('webgl')

得到 webgl 绘制的 context, 通过 context 对象调用 API

  • gl.clearColor(0.0, 0.0, 0.0, 1.0)

设置 clear color , RGBA 格式,取值范围 0-1

  • gl.clear(gl.COLOR_BUFFER_BIT)

用之前设置的 clear color 来填充 color buffer。
buffer 其实就是一块内存空间,color buffer 中的内容会显示在 canvas 中。
底层除了 color buffer 还有 depth(深度) buffer 、stencil(模板) buffer。分别通过 gl.COLOR_BUFFER_BIT、gl.DEPTH_BUFFER_BIT、gl.STENCIL_BUFFER_BIT 来标识。可通过 或 (|) 来指定多个 buffer。

查看源码

相关文章

  • webgl 2.清屏

    所有 code 已在 Chrome 最新版中测试通过源码请查看 https://github.com/leslie...

  • 2. WebGL Browser Compatibility

    Unity WebGL在某种程度上支持所有主流桌面浏览器。但是,不同浏览器之间的支持级别和预期性能会有所不同。请参...

  • css好文章

    1.纯css实现海洋生物图2.地图webGL

  • 产品功能调研——花椒和映客直播详情页

    1.花椒和映客直播详情页功能对比: 2.相同点: 全屏直播 控件悬浮:均支持清扫屏幕(花椒下滑清屏、映客右滑清屏)...

  • 清屏

    1、File->Preferences->Keyboard Shortcuts 2、输入框输入workbench....

  • Linux 命令大全 持续ing

    1.查找文件 find . -name "your file" 2.清屏 control + L 3.中止 con...

  • Git基础命令记录

    clear : 终端清屏command + k : 终端清屏 添加配置 git config [--local |...

  • WebGL漫游之旅(一)

    原文链接:WebGL漫游之旅(一) 一、WebGL基本概念 WebGL (Web Graphics Library...

  • threejs Light

    WebGL and Threejs: Lightig 什么是webgl和threejs? webgl是一个在浏览器...

  • threejs Light

    WebGL and Threejs: Lightig 什么是webgl和threejs? webgl是一个在浏览器...

网友评论

      本文标题:webgl 2.清屏

      本文链接:https://www.haomeiwen.com/subject/eppedxtx.html