I do not understand why I lose readpixel values inside the requestanimationframe loop?
var pixels = new Uint8Array(12*12*4);
gl.clearColor(0.5, 0.8, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);
gl.readPixels(0, 0, 12, 12, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
console.log(pixels[0]); //OK 128 !
anim();
function anim() {
var pixels2 = new Uint8Array(12*12*4);
gl.readPixels(0, 0, 12, 12, gl.RGBA, gl.UNSIGNED_BYTE, pixels2);
console.log(pixels2[0]); // STRANGE : 0 ????
requestAnimationFrame(anim);
}
obviously, if I add
gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);
inside the anim() {...} , the value is 128. But without that gl.clear, why there is a black clear ?