首页 > 代码库 > 着色器传值,控制点的位置和大小
着色器传值,控制点的位置和大小
function main(){ var canvas = document.getElementById("webgl"); var gl = getWebGLContext(canvas) if (!gl){ console.log("Fail to get WebGL context"); return; }else{ ; } var VSHADER_SOURCE = function(){ /* attribute vec4 a_Position; attribute float a_PointSize; void main(){ gl_Position = a_Position; gl_PointSize = a_PointSize; } */ }.toString().match(/\/\*([^]*)\*\//)[1]; var FSHADER_SOURCE = function(){ /* void main(){ gl_FragColor = vec4(1.0,0.0,0.0,1.0); } */ }.toString().match(/\/\*([^]*)\*\//)[1]; if (!initShaders(gl,VSHADER_SOURCE,FSHADER_SOURCE)){ console.log(‘Fail to init shaders‘); return; } var a_Position = gl.getAttribLocation(gl.program,"a_Position"); if (a_Position < 0){ console.log("Fail to get the storage location."); return; } var a_PointSize = gl.getAttribLocation(gl.program,"a_PointSize"); if (a_PointSize < 0){ console.log("Fail to get the storage location."); return; } gl.clearColor(0.0,0.0,0.0,0.8); gl.clear(gl.COLOR_BUFFER_BIT); for (var i=0;i<10;i++){ gl.vertexAttrib3f(a_Position,(i+1)*0.1,(i+1)*0.1,0.0); gl.vertexAttrib1f(a_PointSize, Math.random()*10); gl.drawArrays(gl.POINTS, 0, 1); } }
着色器传值,控制点的位置和大小
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。