]>
git.r.bdr.sh - rbdr/lissajous/blob - lib/webgl_utils.js
1386bf71bbbf18ce18303378a2f5234b207e0f35
2 * Initializes the WebGL Shader program
4 export function initializeShaderProgram(gl
, vertexShaderSource
, fragmentShaderSource
) {
6 const vertexShader
= loadShader(gl
, gl
.VERTEX_SHADER
, vertexShaderSource
);
7 const fragmentShader
= loadShader(gl
, gl
.FRAGMENT_SHADER
, fragmentShaderSource
);
9 const shaderProgram
= gl
.createProgram();
10 gl
.attachShader(shaderProgram
, vertexShader
);
11 gl
.attachShader(shaderProgram
, fragmentShader
);
13 gl
.linkProgram(shaderProgram
);
15 if (!gl
.getProgramParameter(shaderProgram
, gl
.LINK_STATUS
)) {
16 console
.error(`Unable to initialize shader program: ${gl.getProgramInfoLog(shaderProgram)}`);
24 * Initializes the buffers
26 export function initializeBuffers(gl
) {
28 const positionBuffer
= gl
.createBuffer();
30 gl
.bindBuffer(gl
.ARRAY_BUFFER
, positionBuffer
);
33 position: positionBuffer
38 function loadShader(gl
, type
, source
) {
40 const shader
= gl
.createShader(type
);
41 gl
.shaderSource(shader
, source
);
42 gl
.compileShader(shader
);
44 if (!gl
.getShaderParameter(shader
, gl
.COMPILE_STATUS
)) {
45 console
.error(`Unable to compile shader: ${gl.getShaderInfoLog(shader)}`);
46 gl
.deleteShader(shader
);