简体   繁体   English

如何使用glReadPixels获取浮点值? [Android NDK es3.0]

[英]How can I get float values using glReadPixels? [Android NDK es3.0]

c++ code: C ++代码:

float* data = (float*)malloc(texWidth*texHeight*sizeof(float)); // or GLfloat
float* result = (float*)malloc(texWidth*texHeight*sizeof(float)); // or GLfloat
for (int i = 0; i < texWidth * texHeight; i++) {
    data[i] = 2.22;
}
...
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
...
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
...
glReadPixels(0, 0, texWidth, texHeight, GL_RGBA, GL_UNSIGNED_BYTE, result);
for (int i = 0; i < 64; i++) {
    LOGD("%f", result[i]);
}

Now I want to read the value "2.22" back, but now what I get are some long float values. 现在,我想读回值“ 2.22”,但是现在我得到的是一些长浮点值。 (the output is like -188856716075009999660373357998301511680.000000, not I want). (输出就像-188856716075009999660373357998301511680.000000,不是我想要的)。

I also tried using GLubyte as result array's type, and got the color values(result[0] is R value, result[1] is G value, result[2] is B value, result[3] is A value),which is not what I want. 我还尝试使用GLubyte作为结果数组的类型,并获得了颜色值(result [0]是R值,result [1]是G值,result [2]是B值,result [3]是A值),不是我想要的

Questions: 问题:

  1. Since the type is GL_UNSIGNED_BYTE, should I use GLubyte as my array's type? 由于类型是GL_UNSIGNED_BYTE,我应该使用GLubyte作为数组的类型吗?
  2. How can I exactly get the 2.22 through glReadPixels? 如何通过glReadPixels准确地获得2.22?
  3. Can GL_FLOAT be the type of glReadPixels in GLES? GL_FLOAT是否可以是GLES中的glReadPixels类型?
  1. Yes. 是。 Readback format has to match the texture format. 回读格式必须与纹理格式匹配。
  2. You can't, as you are not reading back float data. 您不能,因为您没有回读浮点数据。 You'll have to reconstruct it yourself from the byte values. 您必须根据字节值自己重建它。
  3. Yes, if the texture is a float format texture (OpenGL ES 3.0 onwards) 是的,如果纹理是浮动格式纹理(从OpenGL ES 3.0开始)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM