glReadPixels(): reading order of color-channels (RGB)

Hello everyone,

Not only am I new to OpenGL but fairly new to programming in general, so I apologise if I’m not making much sense. I am currently working on a program that essentially takes a screenshot of RGB and Z and stores them in two separate image files. Since I am working with brownish-grey textures it took me a while to realize that I was getting the R and B channels swapped around (this persists whether I read RGB or RGBA). Mitigating this is trivial but now I wonder:

Am I reading the channels in this order because of my GPU’s configuration, or is it how OpenGL always saves the data? If it has to do with my computer’s architecture, is there a way for me to query in which order the channels will be represented in the data?

Thank you for taking the time to ponder my discoloration.

https://registry.khronos.org/OpenGL-Refpages/gl4/html/glReadPixels.xhtml

You can use GL_BGR or GL_BGRA as the format parameter to glReadPixels.

In general, BGRA is the preferred format and the most likely to work best if you’re using glReadPixels in a performance-critical codepath. For screenshots just pick whichever is most convenient for you (OpenGL will do a format-conversion internally).