How can I flip the result of WebGLRenderingContext.readPixels()?

前端 未结 3 717
无人及你
无人及你 2021-01-14 02:55

Why is the imageData that I get from WebGLRenderingContext.readPixels() upside down?

I try to do the folowing:

var gl = renderer.domElem         


        
3条回答
  •  情深已故
    2021-01-14 03:31

    You can flip pixels of ImadaData directly like this.

    const imageData = new ImageData(Uint8ClampedArray.from(pixels),gl.drawingBufferWidth,gl.drawingBufferHeight);
    
    const w = imageData.width, h = imageData.height;
    const data = imageData.data;
    Array.from({length: h}, (val, i) => data.slice(i * w * 4, (i + 1) * w * 4))
            .forEach((val, i) => data.set(val, (h - i - 1) * w * 4));
    

提交回复
热议问题