当前位置: 首页 > news >正文

家里公网宽带做网站要备案么广州番禺发布

家里公网宽带做网站要备案么,广州番禺发布,网页设计需要学什么编程语言,惠州市建设局人员备案网站目录 uniform变量命名规范 获取 uniform 变量的存储地址 gl.getUniformLocation 向uniform变量赋值 gl.uniform4f ​编辑 gl.uniform4f()的同族函数 demo:点击webgl坐标系的四个象限绘制各自不同颜色的点 uniform变量命名规范 var FSHADER_SOURCE uniform vec4…

目录

uniform变量命名规范

获取 uniform 变量的存储地址 gl.getUniformLocation

向uniform变量赋值 gl.uniform4f

​编辑 gl.uniform4f()的同族函数

demo:点击webgl坐标系的四个象限绘制各自不同颜色的点


uniform变量命名规范

 

var FSHADER_SOURCE ='uniform vec4 u_FragColor;\n' + 'void main() {\n' +'  gl_FragColor = u_FragColor;\n' +'}\n';

着色器将 uniform 变量 u_FragColor 赋值给 gl_FragColor,后者直接决定点的颜色,向 uniform 变量传数据的方式与向 attribute 变量传数据相似:首先获取变量的存储地址,然后在JS程序中按照地址将数据传递过去

获取 uniform 变量的存储地址 gl.getUniformLocation

可以使用以下方法来获取uniform变量的存储地址。

 

 var u_FragColor = gl.getUniformLocation(gl.program, 'u_FragColor');if (!u_FragColor) {console.log('Failed to get the storage location of u_FragColor');return;}

这个函数的功能和参数与 gl.getAttribLocation() 一样,但是如果uniform变量不存在或者其命名使用了保留字前缀,那么函数的返回值将是null而不是-1(gl.getAttribLocation()在此情况下返回-1)。因此,在获取uniform变量的存储地址后,需要检查其是否为null

向uniform变量赋值 gl.uniform4f

有了uniform变量的存储地址,就可以使用WebGL函数 gl.uniform4f() 向变量中写入数据,该函数的功能和参数与 gl.vertexAttrib[1234]f() 类似

gl.uniform4f(u_FragColor, r, g, b, a);

 gl.uniform4f()的同族函数

gl.uniform4f()也有一系列同族函数。gl.uniform1f()函数用来传输1个值(v0),gl.uniform2f()传输2个值(v0和v1),gl.uniform3f()传输3个值(v0,v1和v2)。

demo:点击webgl坐标系的四个象限绘制各自不同颜色的点

 

var VSHADER_SOURCE ='attribute vec4 a_Position;\n' +'void main() {\n' +'  gl_Position = a_Position;\n' +'  gl_PointSize = 10.0;\n' +'}\n';var FSHADER_SOURCE ='precision mediump float;\n' +'uniform vec4 u_FragColor;\n' + 'void main() {\n' +'  gl_FragColor = u_FragColor;\n' +'}\n';function main() {var canvas = document.getElementById('webgl');var gl = getWebGLContext(canvas);if (!gl) {console.log('Failed to get the rendering context for WebGL');return;}if (!initShaders(gl, VSHADER_SOURCE, FSHADER_SOURCE)) {console.log('Failed to intialize shaders.');return;}var a_Position = gl.getAttribLocation(gl.program, 'a_Position');if (a_Position < 0) {console.log('Failed to get the storage location of a_Position');return;}var u_FragColor = gl.getUniformLocation(gl.program, 'u_FragColor');if (!u_FragColor) {console.log('Failed to get the storage location of u_FragColor');return;}// 注册点击事件canvas.onmousedown = function(ev){ click(ev, gl, canvas, a_Position, u_FragColor) };gl.clearColor(0.0, 0.0, 0.0, 1.0);// Clear <canvas>gl.clear(gl.COLOR_BUFFER_BIT);
}var g_points = [];  // The array for the position of a mouse press
var g_colors = [];  // The array to store the color of a point
function click(ev, gl, canvas, a_Position, u_FragColor) {var x = ev.clientX; // x coordinate of a mouse pointervar y = ev.clientY; // y coordinate of a mouse pointervar rect = ev.target.getBoundingClientRect();x = ((x - rect.left) - canvas.width/2)/(canvas.width/2);y = (canvas.height/2 - (y - rect.top))/(canvas.height/2);// 将点存储到g_points数组中g_points.push([x, y]);// 将点的颜色存储到g_colors数组中if (x >= 0.0 && y >= 0.0) {      // 如果点在第一象限g_colors.push([1.0, 0.0, 0.0, 1.0]);  // 红色} else if (x < 0.0 && y < 0.0) { // 如果点在第三象限g_colors.push([0.0, 1.0, 0.0, 1.0]);  // 绿色} else {                         // 否则g_colors.push([1.0, 1.0, 1.0, 1.0]);  // 白色}// 每次绘制前必须显示清除gl.clear(gl.COLOR_BUFFER_BIT);var len = g_points.length;for(var i = 0; i < len; i++) {var xy = g_points[i];var rgba = g_colors[i];// 将点的位置传递给a_position变量gl.vertexAttrib3f(a_Position, xy[0], xy[1], 0.0);// 将点的颜色传递给u_FragColor变量gl.uniform4f(u_FragColor, rgba[0], rgba[1], rgba[2], rgba[3]);// Drawgl.drawArrays(gl.POINTS, 0, 1);}
}

 

 

http://www.tj-hxxt.cn/news/25001.html

相关文章:

  • 基于ssm框架的购物网站开发免费的网络推广平台
  • 可以查企业备案的网站吗重庆seo整站优化
  • 网站发布小说封面怎么做百度怎么打广告在首页
  • 优化网站排名提高关键词排名优化是什么意思
  • 做网站字体用什么格式h5页面制作平台
  • 做网站浏览器标签一般放哪seo网络推广教程
  • 武汉做商城网站建设上海优化网站
  • 温岭网站建设外链图片
  • 网站建设为了什么百度搜索指数在线查询
  • 太原专业设计网页公司珠海百度关键字优化
  • 网站建设简讯武汉整站seo数据上云
  • 昆明做网站的营业推广的方式有哪些
  • 网上最可靠的保险平台重庆seo技术
  • 顺德网站定制设计个人seo怎么赚钱
  • 网站设计与制作优点seo助手
  • 贵阳网站备案网站排名优化公司哪家好
  • 网站权重转移做排名seo外包服务专家
  • 做网站顺序知乎推广公司
  • 给企业建设网站的意义seo具体是什么
  • 网站例子优化王
  • 网站图片导入wordpressseo搜索引擎推广
  • 外贸平台哪个网站最好批发东莞百度seo电话
  • 北京网站开发培训班推广任务接单平台
  • 大学生应届毕业生招聘官网seo推广和百度推广的区别
  • 长春市长春网站建设推广运营是做什么的
  • 网店的网站设计方案抖音信息流广告怎么投放
  • 大良网站建设基本流程怎么推广自己的微信号
  • 汉口做网站jw100网站推广的方式有哪些?
  • 旧房翻新装修多少钱一平方广西seo公司
  • 网站认证是什么厦门seo优化多少钱