当前位置:网站首页>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;**
边栏推荐
- MongoDB数据库基础知识整理
- Compile advanced notes
- Niuke real problem programming - Day17
- Unity's ASE realizes cartoon flame
- Super signature principle (fully automated super signature) [Yun Xiaoduo]
- 【数字IC验证快速入门】24、SystemVerilog项目实践之AHB-SRAMC(4)(AHB继续深入)
- HW初级流量监控,到底该怎么做
- HPDC smart base Talent Development Summit essay
- 【数字IC验证快速入门】29、SystemVerilog项目实践之AHB-SRAMC(9)(AHB-SRAMC SVTB Overview)
- 【OBS】RTMPSockBuf_ Fill, remote host closed connection.
猜你喜欢

15. Using the text editing tool VIM

Ctfshow, information collection: web14

Starting from 1.5, build a microservice framework link tracking traceid

知否|两大风控最重要指标与客群好坏的关系分析

【数字IC验证快速入门】20、SystemVerilog学习之基本语法7(覆盖率驱动...内含实践练习)

【数据挖掘】视觉模式挖掘:Hog特征+余弦相似度/k-means聚类

CTFshow,信息搜集:web4
![[data mining] visual pattern mining: hog feature + cosine similarity /k-means clustering](/img/a4/7320f5d266308f6003cc27964e49f3.png)
[data mining] visual pattern mining: hog feature + cosine similarity /k-means clustering

【兰州大学】考研初试复试资料分享

Mathematical modeling -- what is mathematical modeling
随机推荐
Jacobo code coverage
Runnable是否可以中断
How to release NFT in batches in opensea (rinkeby test network)
【數字IC驗證快速入門】20、SystemVerilog學習之基本語法7(覆蓋率驅動...內含實踐練習)
【服务器数据恢复】戴尔某型号服务器raid故障的数据恢复案例
【原创】一切不谈考核的管理都是扯淡!
Ctfshow, information collection: web10
What are the safest securities trading apps
HPDC smart base Talent Development Summit essay
Ctfshow, information collection: web14
The difference between full-time graduate students and part-time graduate students!
2022 all open source enterprise card issuing network repair short website and other bugs_ 2022 enterprise level multi merchant card issuing platform source code
Use cpolar to build a business website (2)
微信小程序 01
How to build your own super signature system (yunxiaoduo)?
Unity之ASE实现卡通火焰
Win10 or win11 taskbar, automatically hidden and transparent
[机缘参悟-40]:方向、规则、选择、努力、公平、认知、能力、行动,读3GPP 6G白皮书的五层感悟
CTFshow,信息搜集:web4
MySQL bit type resolution