51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
function drawScene(gl, programInfo, buffers, time) {
|
|
gl.clearColor(0.0, 0.0, 0.0, 1.0); // Clear to black, fully opaque
|
|
gl.clearDepth(1.0); // Clear everything
|
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
|
|
// NOTE: this is how width/height is taken
|
|
// const aspect = gl.canvas.clientWidth / gl.canvas.clientHeight;
|
|
|
|
// Tell WebGL how to pull out the positions from the position
|
|
// buffer into the vertexPosition attribute.
|
|
setPositionAttribute(gl, buffers, programInfo);
|
|
|
|
gl.useProgram(programInfo.program);
|
|
|
|
/* --- Set Uniform Variables --- */
|
|
// Time since page loaded in seconds
|
|
gl.uniform1f(
|
|
programInfo.uniformLocations.time,
|
|
time,
|
|
);
|
|
|
|
{
|
|
const offset = 0;
|
|
const vertexCount = 4;
|
|
gl.drawArrays(gl.TRIANGLE_STRIP, offset, vertexCount);
|
|
}
|
|
}
|
|
|
|
// Tell WebGL how to pull out the positions from the position
|
|
// buffer into the vertexPosition attribute.
|
|
function setPositionAttribute(gl, buffers, programInfo) {
|
|
const numComponents = 2; // pull out 2 values per iteration
|
|
const type = gl.FLOAT; // the data in the buffer is 32bit floats
|
|
const normalize = false; // don't normalize
|
|
const stride = 0; // how many bytes to get from one set of values to the next
|
|
// 0 = use type and numComponents above
|
|
const offset = 0; // how many bytes inside the buffer to start from
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers.position);
|
|
gl.vertexAttribPointer(
|
|
programInfo.attribLocations.vertexPosition,
|
|
numComponents,
|
|
type,
|
|
normalize,
|
|
stride,
|
|
offset,
|
|
);
|
|
gl.enableVertexAttribArray(programInfo.attribLocations.vertexPosition);
|
|
}
|
|
|
|
export { drawScene };
|
|
|