1 Star 0 Fork 3

风雨里追赶/Learning-WebGL

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ex02.html 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
andyque 提交于 2014-07-11 06:46 . modify program
<!DOCTYPE html>
<html>
<canvas id ='c' width='480' height='320'></canvas>
<script src='webgl_utils.js'></script>
<script>
var canvas = document.getElementById('c');
var names = ["webgl",
"experimental-webgl",
"webkit-3d",
"moz-webgl"];
var gl;
for (var i = 0; i < names.length; ++i) {
try {
gl = canvas.getContext(names[i]);
}
catch(e) {}
if (gl) break;
}
if (gl == null){
alert("WebGL is not available");
}
gl.clearColor(0,0,0.8,1);
gl.clear(gl.COLOR_BUFFER_BIT);
var vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
var vertices = [-0.5, -0.5, 0.5, -0.5, 0, 0.5];
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices),gl.STATIC_DRAW);
//setup for the vertex shader and fragment shader
var vs = 'attribute vec2 pos;' +
'void main(){ gl_Position = vec4(pos,0,1);}';
var fs = 'precision mediump float;' +
'void main(){ gl_FragColor = vec4(0,0.8,0,1);}';
var program = createProgram(gl,vs,fs);
gl.useProgram(program);
program.vertexPosAttrib = gl.getAttribLocation(program,'pos');
gl.enableVertexAttribArray(program.vertexPosAttrib);
gl.vertexAttribPointer(program.vertexPosAttrib, 2, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.TRIANGLES,0,3);
</script>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/tomblacktan/Learning-WebGL.git
git@gitee.com:tomblacktan/Learning-WebGL.git
tomblacktan
Learning-WebGL
Learning-WebGL
master

搜索帮助