当前位置:网站首页>Getting started with webgl (3)
Getting started with webgl (3)
2022-07-07 15:39:00 【Vegetable chicken on the road】
Use attribute Variable
Purpose of use : Transfer location information from js Passed to vertex shaders in code , There are two main ways ,attribute Variables and uniform Variable ;
attribute Variable : Data related to vertices ;
uniform Variable : So the vertices are the same ( Vertex independent ) data .
Code up :
// Vertex shader program
var VSHADER_SOURCE =
'attribute vec4 a_Position;\n'+
'void main() {\n' +
' gl_Position = a_Position ;\n' +
' gl_PointSize = 30.0;\n' +
'}\n';
// Chip shader program
var FSHADER_SOURCE =
'void main() {\n' +
' gl_FragColor = vec4(1.0, 0.5, 0.0, 1.0);\n' +
'}\n';
function main() {
// obtain <canvas> Elements
var canvas = document.getElementById('webgl');
// obtain WebGL Rendering context
var gl = getWebGLContext(canvas);
if (!gl) {
console.log('Failed to get the rendering context for WebGL');
return;
}
// Initialize shaders
if (!initShaders(gl, VSHADER_SOURCE, FSHADER_SOURCE)) {
console.log('Failed to intialize shaders.');
return;
}
// obtain attribute Storage location
let a_Position = gl.getAttribLocation(gl.program,"a_Position");
if(a_Position < 0){
console.log(" Failed to get storage location !");
return;
}
// Pass the vertex position to attribute Variable
// gl.vertexAttrib1f(a_Position,0.0);
// gl.vertexAttrib2f(a_Position,0.0,0,0);
gl.vertexAttrib3f(a_Position,0.0,0.0,0.0);
// Specify empty <canvas> The color of the
gl.clearColor(0.0, 0.0, 0.0, 1.0);
// Empty <canvas>
gl.clear(gl.COLOR_BUFFER_BIT);
// Draw a point
gl.drawArrays(gl.POINTS, 0, 1);
}
Above , The process is :
(1)attribute vec4 a_Position Variables are declared in attribute, Must be a global variable , Passed in from outside the shader ;
(2) Use getAttribLocation Method to get attribute The address of the variable , The value returned >=0 It means that the address of the variable is returned ,=-1 It means that the variable does not exist ;
(3) Use vertexAttrib3f Method pass value .
This method has 3 Homologous functions , Represents the incoming 1-4 It's worth ,, The length of the array of numbers to be changed in the function . If declared attribute A variable is vec4 type , Only incoming 1 Parameters , The default complement of the last two components is 0.0, The last component is 1.0;
(4) draw , Or draw a dot , It's just to change the way of external value transfer
边栏推荐
- [quick start of Digital IC Verification] 24. AHB sramc of SystemVerilog project practice (4) (AHB continues to deepen)
- 微信小程序 01
- Connecting FTP server tutorial
- Ctfshow, information collection: web12
- CTFshow,信息搜集:web2
- Change win10 Screensaver
- [deep learning] semantic segmentation experiment: UNET network /msrc2 dataset
- Introduction of mongod management database method
- 【跟着江科大学Stm32】STM32F103C8T6_PWM控制直流电机_代码
- Oracle control file loss recovery archive mode method
猜你喜欢

微信小程序 01

Write a ten thousand word long article "CAS spin lock" to send Jay's new album to the top of the hot list

什么是数据泄露

Keil5 does not support online simulation of STM32 F0 series

Ctfshow, information collection: web6
![[deep learning] semantic segmentation experiment: UNET network /msrc2 dataset](/img/69/9dadeb92f8d6299250a894690c2845.png)
[deep learning] semantic segmentation experiment: UNET network /msrc2 dataset

Yunxiaoduo software internal test distribution test platform description document
![[quick start of Digital IC Verification] 20. Basic grammar of SystemVerilog learning 7 (coverage driven... Including practical exercises)](/img/d3/cab8a1cba3c8d8107ce4a95f328d36.png)
[quick start of Digital IC Verification] 20. Basic grammar of SystemVerilog learning 7 (coverage driven... Including practical exercises)

HW primary flow monitoring, what should we do
![[target detection] yolov5 Runtong voc2007 data set](/img/b3/b7f3d46075cb1782d772a24362003e.png)
[target detection] yolov5 Runtong voc2007 data set
随机推荐
【目标检测】YOLOv5跑通VOC2007数据集
【数字IC验证快速入门】26、SystemVerilog项目实践之AHB-SRAMC(6)(APB协议基本要点)
[quick start of Digital IC Verification] 19. Basic grammar of SystemVerilog learning 6 (thread internal communication... Including practical exercises)
【搞船日记】【Shapr3D的STL格式转Gcode】
有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?
Steps to create P8 certificate and warehousing account
最安全的证券交易app都有哪些
[understanding of opportunity -40]: direction, rules, choice, effort, fairness, cognition, ability, action, read the five layers of perception of 3GPP 6G white paper
How to create Apple Developer personal account P8 certificate
How to deploy the super signature distribution platform system?
【數據挖掘】視覺模式挖掘:Hog特征+餘弦相似度/k-means聚類
大表delete删数据导致数据库异常解决
Database exception resolution caused by large table delete data deletion
What is Base64?
Super simple and fully automated generation super signature system (cloud Xiaoduo minclouds.com cloud service instance), free application in-house test app distribution and hosting platform, maintenan
2. Basic knowledge of golang
【服务器数据恢复】戴尔某型号服务器raid故障的数据恢复案例
Ctfshow, information collection: web12
How to build your own super signature system (yunxiaoduo)?
Share the technical details of super signature system construction