gpt4 book ai didi

java - glReadPixels 返回错误值

转载 作者:行者123 更新时间:2023-11-29 06:45:08 24 4
gpt4 key购买 nike

我尝试获取渲染像素的颜色。

gl.glColor3f(1f, 0, 0);
//draw
gl.glReadPixels(lastX - pw / 2, MyCanvas.this.getHeight()
- (lastY - ph / 2), pw, ph, GL.GL_RED, GL.GL_FLOAT,
pixelBuffer);
float r, g, b;
r = pixelBuffer.getFloat();
g = pixelBuffer.getFloat();
b =pixelBuffer.getFloat();
pixelBuffer.rewind();
System.out.println(r+" "+g+" "+b);

屏幕上出现了真正的纯红色,但是glReadPixels返回的r值很奇怪4.6006E-41,为什么???

最佳答案

glReadPixels documentation说:

Storage parameters set by glPixelStore, such as GL_PACK_LSB_FIRST and GL_PACK_SWAP_BYTES, affect the way that data is written into memory.

因此请检查您的glPixelStore 配置。也就是说,您的字节顺序是向后的。

0x0000803F => 4.600602988224807e-41
0x3F800000 => 1.0

有用的链接:

关于java - glReadPixels 返回错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6169378/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com