ReadPixels from WebGL canvas

两盒软妹~` 提交于 2021-02-09 11:12:56

问题


I am trying to save an animation which is created with WebGL on this page. I'd like to store the RGBA values of the animation as an array on my hard drive. Therefore, I tried to use the readPixels method to access the data in javascript to save them. But there are always just zeros written into the array.

I tried this code to read the data from the 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 save the RGBA data of the canvas' animation on my hard drive?


回答1:


are you reading directly after rendering as in

render();
gl.readPixels()

or are you reading in some other event? If you're reading in another event then the drawingBuffer is being cleared as per the spec.

see: https://stackoverflow.com/a/44534528/128511



来源:https://stackoverflow.com/questions/44869599/readpixels-from-webgl-canvas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!