evanw / glfx.js

An image effects library for JavaScript using WebGL
https://evanw.github.io/glfx.js/
MIT License
3.28k stars 403 forks source link

Error: WebGL warning: readPixels: Incompatible format or type. #47

Open webciter opened 6 years ago

webciter commented 6 years ago

Error: WebGL warning: readPixels: Incompatible format or type. When using the getPixelArray(). I need the function getImageData() from the context how can i get this.

Zaphiruz commented 6 years ago

I was having the same issue and got around it using this

// this.canvas is the canvas created with glfx

getPixels() {
        let texture = this.canvas._.texture,
            gl = texture.gl,
            size = texture.width * texture.height * 4,
            pixels = new Uint8Array(size);

        texture.use();
        gl.defaultShader.drawRect();
        gl.readPixels(0, 0, texture.width, texture.height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);

        return pixels;
    }

i used chunks of the source code from Canvas.toImage