I am trying to update the texture inside a framebuffer in REGL. But for some reason, it does not update the framebuffer.
here is the full code:
const regl = createREGL({
extensions: 'OES_texture_float'
})
const initialTexture = regl.texture([
[
[0, 255, 0, 255]
]
])
const fbo = regl.framebuffer({
color: initialTexture,
depth: false,
stencil: false,
})
const updateColor = regl({
framebuffer: () => fbo,
vert: `
precision mediump float;
attribute vec2 position;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
}
`,
frag: `
precision mediump float;
void main() {
gl_FragColor = vec4(255.0, 0.0, 0.0, 255.0);
}
`,
attributes: {
// a triangle big enough to fill the screen
position: [
-4, 0,
4, 4,
4, -4
],
},
count: 3,
})
regl.clear({
// background color (black)
color: [0, 0, 0, 1],
depth: 1,
});
updateColor(() => {
console.log(regl.read())
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/regl/1.3.11/regl.min.js"></script>
- I set the
initialTexture
to green. - In the
updateColor
command I specify the framebuffer making regl render to the framebuffer - The fragment shader in
updateColor
renders a red color - After the
updateColor
command has run, I expected theinitialTexture
to be red, but it stays green.
What am I doing wrong?