简体   繁体   中英

Why glReadPixels return unexpected color format value?

I want to capture screen using Irrlicht with OpenGl ES 1.0 Driver.

Here is my code written in c++

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

Most Android devices work well. But MileStone with Android 2.2.3 got unexpected result.I desire RGBA color format,while MileStone return BGRA color.

At last, I change my code

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

But MileStone return RGBA color.

I have question that why Red and Blue is unexpected? What are the proper reasons?

GL_BGRA is not supported on OpenGL ES. 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. 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 ? 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(...)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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