简体   繁体   English

为什么glReadPixels返回意外的颜色格式值?

[英]Why glReadPixels return unexpected color format value?

I want to capture screen using Irrlicht with OpenGl ES 1.0 Driver. 我想使用Irrlicht和OpenGl ES 1.0 Driver捕获屏幕。

Here is my code written in c++ 这是我用c ++编写的代码

glReadPixels(0, 0, 200, 200, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

Most Android devices work well. 大多数Android设备运行良好。 But MileStone with Android 2.2.3 got unexpected result.I desire RGBA color format,while MileStone return BGRA color. 但是Android 2.2.3的MileStone得到了意想不到的结果。我希望RGBA颜色格式,而MileStone返回BGRA颜色。

At last, I change my code 最后,我改变了我的代码

glReadPixels(0, 0, 200, 200, GL_BGRA, GL_UNSIGNED_BYTE, pixels);

But MileStone return RGBA color. 但是MileStone会返回RGBA颜色。

I have question that why Red and Blue is unexpected? 我有疑问为什么红色和蓝色出乎意料? What are the proper reasons? 原因是什么?

GL_BGRA is not supported on OpenGL ES. OpenGL ES 不支持 GL_BGRA Probably it works on those other devices because of some extension that you implicitly assume to be supported. 可能它适用于其他设备,因为您隐含地假设支持某些扩展。

I would expect OpenGL to set a GL_INVALID_ENUM error code in this case. 我希望OpenGL在这种情况下设置GL_INVALID_ENUM错误代码。 Did you check for that? 你检查过了吗?

Edit: hang on, I didn't read your question correctly. 编辑:坚持,我没有正确阅读你的问题。 So MileStone is swapping the results of GL_RGBA and GL_BGRA ? 那么MileStone是否正在交换GL_RGBAGL_BGRA的结果? That's weird regardless of extensions. 无论扩展如何,这都很奇怪。

If what you are trying to do is to create a Bitmap. 如果你要做的是创建一个位图。 Just use bmp.copyPixelsFromBuffer(...) instead bmp.setPixels(...) 只需使用bmp.copyPixelsFromBuffer(...)代替bmp.setPixels(...)

From the documentation Bitmap : 从文档位图

The data in the buffer is not changed in any way (unlike setPixels(), which converts from unpremultipled 32bit to whatever the bitmap's native format is. The pixels in the source buffer are assumed to be in the bitmap's color space. 缓冲区中的数据不会以任何方式更改(与setPixels()不同,setPixels()从未预设的32位转换为位图的本机格式。假设源缓冲区中的像素位于位图的颜色空间中。

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

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