当前位置:网站首页>Getting started with webgl (2)
Getting started with webgl (2)
2022-07-07 15:38:00 【Vegetable chicken on the road】
1. Draw a point
// Vertex shader program
var VSHADER_SOURCE =
'void main() {\n' +
' gl_Position = vec4(-0.5, -0.5, 0.0, 1.0);\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;
}
// 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);
}
Here we need to talk about the concept of shaders
2. Shaders
webgl There are two kinds of shaders :
(1) Vertex shader ( abbreviation vs): seeing the name of a thing one thinks of its function , It describes the characteristics of vertices , Mainly including location , Color, etc. . It is a point in two-dimensional or three-dimensional space ;
(2) Chip shader ( abbreviation fs): It can be understood as pixels , It is a unit of image , Piece by piece
3. Execution process


4. Execution results

Why is it displayed in the lower left corner ? stay webgl In the system , Divide the display area into four quadrants :
First quadrant :(+,+);
Beta Quadrant :(-,+);
The third quadrant :(-,-);
Quadrant four :(+,-);
**** Other explanations :
gl_Position = vec4(-0.5, -0.5, 0.0, 1.0):vec4 type , Describe the location of x.y.z coordinate , Finally, add a 1.0 As a component , The coordinates are transformed into a homogeneous coordinate .
gl_FragColor = vec4(1.0, 0.5, 0.0, 1.0):vec4 type , Describing color r,g,b,a;**
边栏推荐
- [server data recovery] a case of RAID data recovery of a brand StorageWorks server
- 2. Heap sort "hard to understand sort"
- Yunxiaoduo software internal test distribution test platform description document
- [follow Jiangke University STM32] stm32f103c8t6_ PWM controlled DC motor_ code
- [quick start of Digital IC Verification] 24. AHB sramc of SystemVerilog project practice (4) (AHB continues to deepen)
- Unity's ASE achieves full screen sand blowing effect
- Change win10 Screensaver
- 2. Basic knowledge of golang
- HW初级流量监控,到底该怎么做
- Comparable and comparator of sorting
猜你喜欢
![[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)](/img/91/16a370ac41adc8fe31507765a82b0a.png)
[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)
![[deep learning] semantic segmentation experiment: UNET network /msrc2 dataset](/img/69/9dadeb92f8d6299250a894690c2845.png)
[deep learning] semantic segmentation experiment: UNET network /msrc2 dataset
![[quick start of Digital IC Verification] 29. Ahb-sramc (9) (ahb-sramc svtb overview) of SystemVerilog project practice](/img/f7/03975d08912afd8daee936799e8951.png)
[quick start of Digital IC Verification] 29. Ahb-sramc (9) (ahb-sramc svtb overview) of SystemVerilog project practice

Ctfshow, information collection: web12

How to release NFT in batches in opensea (rinkeby test network)

HW primary flow monitoring, what should we do

【数字IC验证快速入门】29、SystemVerilog项目实践之AHB-SRAMC(9)(AHB-SRAMC SVTB Overview)

【數據挖掘】視覺模式挖掘:Hog特征+餘弦相似度/k-means聚類

CTFshow,信息搜集:web9

Niuke real problem programming - day20
随机推荐
Ctfshow, information collection: Web3
The bank needs to build the middle office capability of the intelligent customer service module to drive the upgrade of the whole scene intelligent customer service
【服务器数据恢复】戴尔某型号服务器raid故障的数据恢复案例
数学建模——什么是数学建模
[quick start of Digital IC Verification] 29. Ahb-sramc (9) (ahb-sramc svtb overview) of SystemVerilog project practice
知否|两大风控最重要指标与客群好坏的关系分析
TypeScript 发布 4.8 beta 版本
How to create Apple Developer personal account P8 certificate
Create lib Library in keil and use lib Library
What is Base64?
简述keepalived工作原理
STM32F103C8T6 PWM驱动舵机(SG90)
最安全的证券交易app都有哪些
[deep learning] image hyperspectral experiment: srcnn/fsrcnn
Ctfshow, information collection: web13
Why do we use UTF-8 encoding?
Ctfshow, information collection: web10
连接ftp服务器教程
【跟着江科大学Stm32】STM32F103C8T6_PWM控制直流电机_代码
Window环境下配置Mongodb数据库