Learning my first WebGL, attempting to draw an image (from url) on a canvas WebGL context.
My goal is to have a background image on the canvas with a transparent image on top, showing the background, to ultimately use captureStream.
While my shaders are compiling successfully (per gl.COMPILE_STATUS) it appears I'm missing a step to a valid program:
const vs = gl.createShader(gl.VERTEX_SHADER)
gl.shaderSource(vs, document.getElementById('draw-image-vertex-shader').innerText)
gl.compileShader(vs)
const fs = gl.createShader(gl.FRAGMENT_SHADER)
gl.shaderSource(fs, document.getElementById('draw-image-fragment-shader').innerText)
gl.compileShader(fs)
var vs_success = gl.getShaderParameter(vs, gl.COMPILE_STATUS);
console.log( vs_success )
var fs_success = gl.getShaderParameter(fs, gl.COMPILE_STATUS);
console.log( fs_success )
const program = gl.createProgram()
gl.useProgram(program)
I'm getting:
WebGL: INVALID_OPERATION: useProgram: program not valid
Here are the shaders:
<script id="draw-image-vertex-shader" type="glsl">
attribute vec4 a_position;
attribute vec2 a_texcoord;
uniform mat4 u_matrix;
varying vec2 v_texcoord;
void main() {
gl_Position = u_matrix * a_position;
v_texcoord = a_texcoord;
}
</script>
<script id="draw-image-fragment-shader" type="glsl">
precision mediump float;
varying vec2 v_texcoord;
uniform sampler2D u_texture;
void main() {
gl_FragColor = texture2D(u_texture, v_texcoord);
}
</script>
Any insight would be amazing, big thanks :)