-
Notifications
You must be signed in to change notification settings - Fork 1
/
webglutils.js
32 lines (25 loc) · 1.01 KB
/
webglutils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export function makeProgram(gl, vertexShaderSrc, fragmentShaderSrc) {
const vertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vertexShader, vertexShaderSrc);
gl.compileShader(vertexShader);
if (gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
console.log("vertex shader compiled successfully");
} else {
console.log("error while compiling vertex shader");
}
console.log(gl.getShaderInfoLog(vertexShader));
const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fragmentShader, fragmentShaderSrc);
gl.compileShader(fragmentShader);
if (gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
console.log("fragment shader compiled successfully");
} else {
console.log("error while compiling fragment shader");
}
console.log(gl.getShaderInfoLog(fragmentShader));
const program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
return program;
}