Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readPixels() with format RGB outputs zero #265

Open
UlyssesZh opened this issue Jul 28, 2023 · 0 comments
Open

readPixels() with format RGB outputs zero #265

UlyssesZh opened this issue Jul 28, 2023 · 0 comments
Labels

Comments

@UlyssesZh
Copy link

const width = 4;
const height = 4;
const gl = require('gl')(width, height, {preserveDrawingBuffer: true});
gl.clearColor(1, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);

const pixelsRgba = new Uint8Array(width * height * 4);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixelsRgba);
console.log(pixelsRgba);

const pixelsRgb = new Uint8Array(width * height * 3);
gl.readPixels(0, 0, width, height, gl.RGB, gl.UNSIGNED_BYTE, pixelsRgb);
console.log(pixelsRgb);

Output:

Uint8Array(64) [
  255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255,
  255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255,
  255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255,
  255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255,
  255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255,
  255, 0, 0, 255
]
Uint8Array(48) [
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0
]

The RGBA output is correct, but the RGB output is incorrect.

@UlyssesZh UlyssesZh changed the title readPixels() with format RGBA outputs zero readPixels() with format RGB outputs zero Jul 28, 2023
@dhritzkiv dhritzkiv added the bug label Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants