function diceGeometry(gl) {
const [A, B, C, D, E] = [
[ 0.0, 1.0, 0.0 ],
[-1.0, 0.0, 1.0 ],
[ 1.0, 0.0, 1.0 ],
[ 1.0, 0.0, -1.0 ],
[-1.0, 0.0, -1.0 ]
];
let posicao = new Float32Array([
...A, ...B, ...C,
...A, ...C, ...D,
...A, ...D, ...E,
...A, ...E, ...B,
...B, ...C, ...D,
...B, ...D, ...E
]);
let textura = new Float32Array([
0, 1/2, 1/3, 1/2, 1/3, 0, 0, 0,
1/3, 1/2, 2/3, 1/2, 2/3, 0, 1/3, 0,
2/3, 1/2, 1, 1/2, 1, 0, 2/3, 0,
0, 1, 1/3, 1, 1/3, 1/2, 0, 1/2,
1/3, 1, 2/3, 1, 2/3, 1/2, 1/3, 1/2,
]);
let index = new Int16Array([
0, 1, 2,
3, 4, 5,
6, 7, 8,
9, 10, 11,
12, 13, 14,
15, 16, 17
]);
let prog = createProgram(gl,vertexShader,fragmentShader,[["a_posicao",0],["a_textura",1]]);
let vao = gl.createVertexArray()
gl.bindVertexArray(vao)
gl.enableVertexAttribArray(0)
gl.enableVertexAttribArray(1)
let posicao_vbo = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER,posicao_vbo);
gl.bufferData(gl.ARRAY_BUFFER,posicao,gl.STATIC_DRAW);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
let textura_vbo = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER,textura_vbo);
gl.bufferData(gl.ARRAY_BUFFER,textura,gl.STATIC_DRAW);
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
let ind_vbo = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,ind_vbo);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,index,gl.STATIC_DRAW);
function draw(uniforms) {
gl.bindVertexArray(vao);
gl.useProgram(prog);
gl.uniformMatrix4fv(gl.getUniformLocation(prog,"model"),false,uniforms.model);
gl.uniformMatrix4fv(gl.getUniformLocation(prog,"view"),false,uniforms.view);
gl.uniformMatrix4fv(gl.getUniformLocation(prog,"projection"),false,uniforms.projection);
gl.uniform1i(gl.getUniformLocation(prog,"u_texture"), 0);
gl.drawElements(gl.TRIANGLES,index.length,gl.UNSIGNED_SHORT,0);
}
return { draw };
}