function initVertexBuffers(gl, vertices) { const vertexBuffer = gl.createBuffer(); if (!vertexBuffer) { console.error("Gagal dalam membuat buffer object!"); return -1; } gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); const a_Position = gl.getAttribLocation(gl.program, "a_Position"); gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, 0, 0); gl.enableVertexAttribArray(a_Position); const n = Math.floor(vertices.length / 2); return n; } function setColor(gl, color) { const u_FragColor = gl.getUniformLocation(gl.program, "u_FragColor"); gl.uniform4f(u_FragColor, ...color); } function drawShape(gl, mode, vertices) { const n = initVertexBuffers(gl, vertices); if (n < 0) { alert("Gagal dalam menginisiasi buffer object!"); return; } gl.drawArrays(mode, 0, n); }