How to create an RGBA window on iOS

Hi,

It seems that on win, Linux and Android the default pixel format for an OpenGL window is RGBA8888, whereas on iOS it’s BGRA8888.

Is there a way to make sdl create an RGBA8888 window on iOS?

Are you sure? SDL?s context creation code for iOS[1] uses kEAGLColorFormatRGBA8, which, according to Apple?s docs: "Specifies a 32-bit RGBA format that corresponds to the OpenGL ES GL_RGBA8888 format.?

[1]: https://hg.libsdl.org/SDL/file/48d4f2d74d67/src/video/uikit/SDL_uikitopenglview.m#l64On Jun 16, 2014, at 5:10 PM, Starg wrote:

Hi,

It seems that on win, Linux and Android the default pixel format for an OpenGL window is RGBA8888, whereas on iOS it’s BGRA8888.

Is there a way to make sdl create an RGBA8888 window on iOS?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

If you don?t set RGB8 or RGBA8 via SDL_GL_SetAttribute then SDL will pick the RGB565 format by default on iOS, though.On Jun 16, 2014, at 5:15 PM, Alex Szpakowski <@Alex_Szpakowski> wrote:

Are you sure? SDL?s context creation code for iOS1 uses kEAGLColorFormatRGBA8, which, according to Apple?s docs: "Specifies a 32-bit RGBA format that corresponds to the OpenGL ES GL_RGBA8888 format.?

On Jun 16, 2014, at 5:10 PM, Starg wrote:

Hi,

It seems that on win, Linux and Android the default pixel format for an OpenGL window is RGBA8888, whereas on iOS it’s BGRA8888.

Is there a way to make sdl create an RGBA8888 window on iOS?

Thanks for the info.
I’ve made my own OpenGL batch renderer but I use sdl to create the window and context.
The colours are all mixed up on iOS, whereas on the other platforms they are fine.

Maybe it’s mixed up because the format is RGB565? When I saw the mixed up colours I just assumed the format was BGRA.
I’ll have a closer look.

The format of the default framebuffer doesn?t affect colors like that, as far as I know. Maybe the issue is in your texture loading code?On Jun 16, 2014, at 6:00 PM, Starg wrote:

Thanks for the info.
I’ve made my own OpenGL batch renderer but I use sdl to create the window and context.
The colours are all mixed up on iOS, whereas on the other platforms they are fine.

Maybe it’s mixed up because the format is RGB565? When I saw the mixed up colours I just assumed the format was BGRA.
I’ll have a closer look.

I load pngs using rwops into an sdl surface.
I then use the surface->pixels pointer when creating a gl texture of type GL_RGBA where each pixel is a byte.
So should that display ok irrespective of the framebuffer format?
If so, then there must be something amiss with the pixel data in the surface?

  • each channel is a byte (not pixel)

Yeah, it might be silently loading PNGs as BGRA instead of RGBA (I know stb_image has code to reverse that effect on iOS.)On Jun 16, 2014, at 6:14 PM, Starg wrote:

I load pngs using rwops into an sdl surface.
I then use the surface->pixels pointer when creating a gl texture of type GL_RGBA where each pixel is a byte.
So should that display ok irrespective of the framebuffer format?
If so, then there must be something amiss with the pixel data in the surface?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Xcode will, by default, convert PNGs to BGRA. To disable this, you need to
change the build settings so that “Compress PNG Images” is disabled.

Right, thanks for the info, I’ll have a look at that tomorrow. Ta!

Xcode will, by default, convert PNGs to BGRA. To disable this, you need to change the build settings so that “Compress PNG Images” is disabled.

@Luke Ah, I didn’t know about that setting. However, turning off ‘Compress PNGs’ doesn’t fix the problem. Also, oddly enough, the PNGs in the package file are bigger when they are ‘compressed’ than when they’re not. (So I know that setting is making some difference)

Yeah, it might be silently loading PNGs as BGRA instead of RGBA (I know stb_image has code to reverse that effect on iOS.)

@Alex Right, I’ve had a look at stb_image code and I can see where the conversion is done. However, I’m using the STL_Image plugin and this doesn’t have this code.
I’ve added something similar in the STL_Image function ‘Create_SDL_Surface_From_CGImage_RGB’ and it works!

Should I look at adding that change back to STL_Image?

However, turning off ‘Compress PNGs’ doesn’t fix the problem. Also, oddly
enough, the PNGs in the package file are bigger when they are 'compressed’
than when they’re not. (So I know that setting is making some difference)

That is actually part of why it’s pretty popular to disable - because it
decompresses/recompresses PNGs as part of this process it tends to wind up
making highly optimized PNGs bigger.

In order to get it to show up you might have to delete the app bundle from
the device then clean/rebuild the app after you’ve disabled the settings -
since the assets themselves never changed my guess is that Xcode hasn’t
marked them as stale and replaced the ones in the app bundle. If that
doesn’t solve the issue then I am not entirely sure what else it would be.On Tue, Jun 17, 2014 at 3:46 AM, Starg wrote: