ReadPixels from WebGL Canvas

I am trying to save animation created with WebGL on this page . I would like to store the RGBA

animation values as an array on my hard drive. So I tried to use the readPixels

data access method in javascript to save it. But the array always contains only zeros.

I tried this code to read data from canvas c

var pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4);
gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels);

      

How can I solve the problem? Are there other ways to store the RGBA canvas animation data on my hard drive?

+3


source to share


1 answer


You are reading directly after rendering, as in

render();
gl.readPixels()

      



or are you reading some other event? If you read another event, then the DrawingBuffer is cleared as per spec.

see below: fooobar.com/questions/433050 / ...

0


source







All Articles