ft bozo but in 3D
This commit is contained in:
20
frontend/static/js/3D/buffers.js
Normal file
20
frontend/static/js/3D/buffers.js
Normal file
@ -0,0 +1,20 @@
|
||||
function initBuffers(gl)
|
||||
{
|
||||
const positionBuffer = initPositionBuffer(gl);
|
||||
|
||||
return { position: positionBuffer };
|
||||
}
|
||||
|
||||
function initPositionBuffer(gl)
|
||||
{
|
||||
const positionBuffer = gl.createBuffer();
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
||||
|
||||
const positions = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
|
||||
|
||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);
|
||||
return positionBuffer;
|
||||
}
|
||||
|
||||
export { initBuffers };
|
28
frontend/static/js/3D/maths/gl-matrix-min.js
vendored
Normal file
28
frontend/static/js/3D/maths/gl-matrix-min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
61
frontend/static/js/3D/shaders.js
Normal file
61
frontend/static/js/3D/shaders.js
Normal file
@ -0,0 +1,61 @@
|
||||
const vertex_shader_source = `
|
||||
attribute vec4 aPos;
|
||||
attribute vec4 aColor;
|
||||
|
||||
uniform mat4 uModView;
|
||||
uniform mat4 uProj;
|
||||
|
||||
varying lowp vec4 vColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = uProj * uModView * aPos;
|
||||
vColor = aColor;
|
||||
}
|
||||
`;
|
||||
|
||||
const fragment_shader_source = `
|
||||
varying lowp vec4 vColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vColor;
|
||||
}
|
||||
`;
|
||||
|
||||
function initShaderProgram(gl)
|
||||
{
|
||||
const vertexShader = loadShader(gl, gl.VERTEX_SHADER, vertex_shader_source);
|
||||
const fragmentShader = loadShader(gl, gl.FRAGMENT_SHADER, fragment_shader_source);
|
||||
|
||||
const shaderProgram = gl.createProgram();
|
||||
gl.attachShader(shaderProgram, vertexShader);
|
||||
gl.attachShader(shaderProgram, fragmentShader);
|
||||
gl.linkProgram(shaderProgram);
|
||||
|
||||
if(!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
|
||||
{
|
||||
alert(`Unable to initialize the shader program: ${gl.getProgramInfoLog(shaderProgram)}`);
|
||||
return null;
|
||||
}
|
||||
return shaderProgram;
|
||||
}
|
||||
|
||||
function loadShader(gl, type, source)
|
||||
{
|
||||
const shader = gl.createShader(type);
|
||||
|
||||
gl.shaderSource(shader, source);
|
||||
gl.compileShader(shader);
|
||||
|
||||
if(!gl.getShaderParameter(shader, gl.COMPILE_STATUS))
|
||||
{
|
||||
alert(`An error occurred compiling the shaders: ${gl.getShaderInfoLog(shader)}`);
|
||||
gl.deleteShader(shader);
|
||||
return null;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
export { initShaderProgram };
|
Reference in New Issue
Block a user