forked from mikael-lovqvist/websperiments
Interactive WebGL Goldberg polyhedron viewer and painter with PBR shading, adjustable environment lighting, paint tools (pen, brush, circle, fill, line, pick), undo/redo, colour palettes, and mesh relaxation. Added to the standalone experiments index. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
24 lines
771 B
JavaScript
24 lines
771 B
JavaScript
export function compile_shader(gl, type, src) {
|
|
const s = gl.createShader(type);
|
|
gl.shaderSource(s, src);
|
|
gl.compileShader(s);
|
|
if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) { throw new Error(gl.getShaderInfoLog(s)); }
|
|
return s;
|
|
}
|
|
|
|
export function create_program(gl, vs_src, fs_src) {
|
|
const p = gl.createProgram();
|
|
gl.attachShader(p, compile_shader(gl, gl.VERTEX_SHADER, vs_src));
|
|
gl.attachShader(p, compile_shader(gl, gl.FRAGMENT_SHADER, fs_src));
|
|
gl.linkProgram(p);
|
|
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) { throw new Error(gl.getProgramInfoLog(p)); }
|
|
return p;
|
|
}
|
|
|
|
export function make_buffer(gl, data) {
|
|
const buf = gl.createBuffer();
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
|
|
gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
|
|
return buf;
|
|
}
|