SDL_CreateTexture and SDL_UpdateTexture uses my pixel format in reverse

I recently ported all of my OpenGL code for rendering to the SDL renderer. Here’s what I’m doing that results in a problem that I have yet to figure out:#1. Load a png file as 32-bit RGBA using the popular lodepng header.#2. Call SDL_CreateTexture with SDL_PIXELFORMAT_RGBA888 and SDL_TEXTUREACCESS_STATIC.#3. Call SDL_UpdateTexture with the pixel data from lodepng with a NULL rect and WIDTH * CHANNELS value for pitch.
The result is the colors are wrong for my image. If I change the pixel format for the texture to SDL_PIXELFORMAT_ABGR8888 my colors look correct! Why is it seeing my pixel format in reverse? When I was using OpenGL for textures I did not have this problem with an unchanged image loading procedure.

Are you testing your code on Android/iOS? SDL’s GLES implementation only
supports SDL_PIXELFORMAT_ARGB8888.
Try using that.On 8/26/2013 8:57 PM, John Tullos wrote:

I recently ported all of my OpenGL code for rendering to the SDL
renderer. Here’s what I’m doing that results in a problem that I have
yet to figure out:
#1. Load a png file as 32-bit RGBA using the popular lodepng header.
#2. Call SDL_CreateTexture with SDL_PIXELFORMAT_RGBA888 and
SDL_TEXTUREACCESS_STATIC.
#3. Call SDL_UpdateTexture with the pixel data from lodepng with a
NULL rect and WIDTH * CHANNELS value for pitch.

The result is the colors are wrong for my image. If I change the pixel
format for the texture to SDL_PIXELFORMAT_ABGR8888 my colors look
correct! Why is it seeing my pixel format in reverse? When I was using
OpenGL for textures I did not have this problem with an unchanged
image loading procedure.


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


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming

I’m buliding this game for Windows and OS X in the future, so why would I want to build it for Android or iOS? Are you saying that SDL_PIXELFORMAT_ARGB8888 is only available with OpenGL ES? Perhaps my problem was misunderstood.
My data is RGBA8888, but SDL doesn’t render it correctly unless I put that data in a texture using the format ABGR8888.> Date: Tue, 27 Aug 2013 11:15:06 +0530

From: pallavnawani at gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL_CreateTexture and SDL_UpdateTexture uses my pixel format in reverse.

Are you testing your code on Android/iOS? SDL’s GLES implementation only
supports SDL_PIXELFORMAT_ARGB8888.
Try using that.

On 8/26/2013 8:57 PM, John Tullos wrote:

I recently ported all of my OpenGL code for rendering to the SDL
renderer. Here’s what I’m doing that results in a problem that I have
yet to figure out:
#1. Load a png file as 32-bit RGBA using the popular lodepng header.
#2. Call SDL_CreateTexture with SDL_PIXELFORMAT_RGBA888 and
SDL_TEXTUREACCESS_STATIC.
#3. Call SDL_UpdateTexture with the pixel data from lodepng with a
NULL rect and WIDTH * CHANNELS value for pitch.

The result is the colors are wrong for my image. If I change the pixel
format for the texture to SDL_PIXELFORMAT_ABGR8888 my colors look
correct! Why is it seeing my pixel format in reverse? When I was using
OpenGL for textures I did not have this problem with an unchanged
image loading procedure.


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


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming


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

Fixed my problem. I was under the impression that I could use any of the formats in the documentation for SDL_CreateTexture, when actually there were only 3 formats I was allowed to use. It was picking a pixel format closest to what mine was which resulted in my problem. Documentation doesn’t guide me in this direction, a note should probably be made for the format parameter.
I used SDL_ConvertPixels to convert my format to the closest format supported by my renderer and all is now working perfectly.From: @John_Tullos
To: sdl at lists.libsdl.org
Date: Tue, 27 Aug 2013 15:57:09 +0000
Subject: Re: [SDL] SDL_CreateTexture and SDL_UpdateTexture uses my pixel format in reverse.

I’m buliding this game for Windows and OS X in the future, so why would I want to build it for Android or iOS? Are you saying that SDL_PIXELFORMAT_ARGB8888 is only available with OpenGL ES? Perhaps my problem was misunderstood.
My data is RGBA8888, but SDL doesn’t render it correctly unless I put that data in a texture using the format ABGR8888.

Date: Tue, 27 Aug 2013 11:15:06 +0530
From: pallavnawani at gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL_CreateTexture and SDL_UpdateTexture uses my pixel format in reverse.

Are you testing your code on Android/iOS? SDL’s GLES implementation only
supports SDL_PIXELFORMAT_ARGB8888.
Try using that.

On 8/26/2013 8:57 PM, John Tullos wrote:

I recently ported all of my OpenGL code for rendering to the SDL
renderer. Here’s what I’m doing that results in a problem that I have
yet to figure out:
#1. Load a png file as 32-bit RGBA using the popular lodepng header.
#2. Call SDL_CreateTexture with SDL_PIXELFORMAT_RGBA888 and
SDL_TEXTUREACCESS_STATIC.
#3. Call SDL_UpdateTexture with the pixel data from lodepng with a
NULL rect and WIDTH * CHANNELS value for pitch.

The result is the colors are wrong for my image. If I change the pixel
format for the texture to SDL_PIXELFORMAT_ABGR8888 my colors look
correct! Why is it seeing my pixel format in reverse? When I was using
OpenGL for textures I did not have this problem with an unchanged
image loading procedure.


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


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming


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


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

If you create a texture of a different format it’s supposed to
automatically convert for you. Can you add a bug with a simple test case
to bugzilla?
http://bugzilla.libsdl.org/

Thanks!On Tue, Aug 27, 2013 at 6:49 PM, John Tullos wrote:

Fixed my problem. I was under the impression that I could use any of the
formats in the documentation for SDL_CreateTexture, when actually there
were only 3 formats I was allowed to use. It was picking a pixel format
closest to what mine was which resulted in my problem. Documentation
doesn’t guide me in this direction, a note should probably be made for the
format parameter.

I used SDL_ConvertPixels to convert my format to the closest format
supported by my renderer and all is now working perfectly.


From: xeek at xeekworx.com
To: sdl at lists.libsdl.org
Date: Tue, 27 Aug 2013 15:57:09 +0000

Subject: Re: [SDL] SDL_CreateTexture and SDL_UpdateTexture uses my pixel
format in reverse.

I’m buliding this game for Windows and OS X in the future, so why would I
want to build it for Android or iOS? Are you saying that SDL_PIXELFORMAT_ARGB8888
is only available with OpenGL ES? Perhaps my problem was misunderstood.

My data is RGBA8888, but SDL doesn’t render it correctly unless I put that
data in a texture using the format ABGR8888.

Date: Tue, 27 Aug 2013 11:15:06 +0530
From: pallavnawani at gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL_CreateTexture and SDL_UpdateTexture uses my pixel
format in reverse.

Are you testing your code on Android/iOS? SDL’s GLES implementation only
supports SDL_PIXELFORMAT_ARGB8888.
Try using that.

On 8/26/2013 8:57 PM, John Tullos wrote:

I recently ported all of my OpenGL code for rendering to the SDL
renderer. Here’s what I’m doing that results in a problem that I have
yet to figure out:
#1. Load a png file as 32-bit RGBA using the popular lodepng header.
#2. Call SDL_CreateTexture with SDL_PIXELFORMAT_RGBA888 and
SDL_TEXTUREACCESS_STATIC.
#3. Call SDL_UpdateTexture with the pixel data from lodepng with a
NULL rect and WIDTH * CHANNELS value for pitch.

The result is the colors are wrong for my image. If I change the pixel
format for the texture to SDL_PIXELFORMAT_ABGR8888 my colors look
correct! Why is it seeing my pixel format in reverse? When I was using
OpenGL for textures I did not have this problem with an unchanged
image loading procedure.


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


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming


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

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


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