WenheLI / p5.gif

P5.js gif helper
MIT License
38 stars 4 forks source link

Add webgl support #12

Closed infusion closed 5 years ago

infusion commented 5 years ago

Hello,

having Webgl support to create gifs would be pretty nice. I think there are not much things needed to add support for it. I hacked a very stupid workaround for the moment, but native support would be much better:

recorder.settings.context = window.canvas.getContext('webgl');
                  recorder.settings.context.getImageData = function(left, top, width, height) {
                    var gl = recorder.settings.context;
                    var pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4);
                    gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
                    return {data: pixels};
                  };

For context, I would like to render pretty gifs of https://www.xarg.org/paper/inverse-kinematics-of-a-stewart-platform/

Thanks Robert

WenheLI commented 5 years ago

Supported by 27da75cc176fc667b07490b8944691b61259c566 . Please set the canvas as WEBGL and init the recorder in this way to use webgl.

function setup() {
  createCanvas(200, 200, WEBGL);
  recorder = p5Gif.capture({framerate: 60, webgl: true});
}