24 lines
674 B
JavaScript
24 lines
674 B
JavaScript
export function setupCanvas(gl, canvas) {
|
|
canvas.width = canvas.clientWidth * window.devicePixelRatio;
|
|
canvas.height = canvas.clientHeight * window.devicePixelRatio;
|
|
gl.viewport(0, 0, canvas.width, canvas.height);
|
|
|
|
return {
|
|
canvas,
|
|
gl,
|
|
aspectRatio: canvas.width / canvas.height,
|
|
};
|
|
}
|
|
|
|
export function resizeCanvas(gl, canvas, program) {
|
|
canvas.width = canvas.clientWidth * window.devicePixelRatio;
|
|
canvas.height = canvas.clientHeight * window.devicePixelRatio;
|
|
gl.viewport(0, 0, canvas.width, canvas.height);
|
|
gl.useProgram(program);
|
|
gl.uniform2f(
|
|
gl.getUniformLocation(program, 'u_resolution'),
|
|
canvas.width,
|
|
canvas.height
|
|
);
|
|
}
|