diff --git a/src/script.js b/src/script.js index be0f7c7..ad76c9d 100644 --- a/src/script.js +++ b/src/script.js @@ -152,6 +152,9 @@ async function draw() { gl.useProgram(program); + let colorLocation = gl.getUniformLocation(program, "color"); + gl.uniform3fv(colorLocation, hexColorToFloatArray("dc3c05")); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); gl.drawArrays(gl.TRIANGLES, 0, vertices.length / 2); @@ -160,4 +163,12 @@ async function draw() { requestAnimationFrame(draw); } +function hexColorToFloatArray(hex) { + let r = parseInt(hex.substring(0, 2), 16) / 255; + let g = parseInt(hex.substring(2, 4), 16) / 255; + let b = parseInt(hex.substring(4, 6), 16) / 255; + + return [r, g, b]; +} + window.addEventListener("DOMContentLoaded", init); \ No newline at end of file diff --git a/src/shaders/vertex.glsl b/src/shaders/vertex.glsl index 581b404..bdfa378 100644 --- a/src/shaders/vertex.glsl +++ b/src/shaders/vertex.glsl @@ -1,10 +1,10 @@ precision mediump float; attribute vec2 vertPosition; -attribute vec3 vertColor; +uniform vec3 color; varying vec3 fragColor; void main() { - fragColor = vertColor; + fragColor = color; gl_Position = vec4(vertPosition, 0.0, 1.0); } \ No newline at end of file