add colour
This commit is contained in:
parent
bf6404cd85
commit
48d3d91aaa
|
@ -152,6 +152,9 @@ async function draw() {
|
||||||
|
|
||||||
gl.useProgram(program);
|
gl.useProgram(program);
|
||||||
|
|
||||||
|
let colorLocation = gl.getUniformLocation(program, "color");
|
||||||
|
gl.uniform3fv(colorLocation, hexColorToFloatArray("dc3c05"));
|
||||||
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
||||||
|
|
||||||
gl.drawArrays(gl.TRIANGLES, 0, vertices.length / 2);
|
gl.drawArrays(gl.TRIANGLES, 0, vertices.length / 2);
|
||||||
|
@ -160,4 +163,12 @@ async function draw() {
|
||||||
requestAnimationFrame(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);
|
window.addEventListener("DOMContentLoaded", init);
|
|
@ -1,10 +1,10 @@
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
|
|
||||||
attribute vec2 vertPosition;
|
attribute vec2 vertPosition;
|
||||||
attribute vec3 vertColor;
|
uniform vec3 color;
|
||||||
varying vec3 fragColor;
|
varying vec3 fragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
fragColor = vertColor;
|
fragColor = color;
|
||||||
gl_Position = vec4(vertPosition, 0.0, 1.0);
|
gl_Position = vec4(vertPosition, 0.0, 1.0);
|
||||||
}
|
}
|
Loading…
Reference in New Issue