Image loaded as wrong color
Closed this issue · 4 comments
The title is unclear, so I will be as clear as possible.
I'm using SDL3's GPU library and I've been loading BMPs using SDL3's built-in functions and everything works fine. In this case, the image I'm loading is mostly blue. When I load the SDL_Surface
using SDL_Image's function, the blue image appears to be yellow and loaded yellow in the Texture buffer. If I save this yellow version of the image and try to load and draw it, the image appears to be blue (which is the original version).
Considering SDL3's image loading works fine with my render logic, I thought the issue might be related to the SDL_Image. Any ideas If I might have done wrong? All I did so far was initialize the library and call the load image function.
It may be an issue in SDL_image, e.g. a missed update against SDL3
changes because SDL3 still is a fast moving target. Which git revision
of SDL_image are you using and which revision of SDL3 did you build it
against?
A minimal reproducer to show how you use SDL_image would be helpful.
CC: @slouken (possibly CC the gpu guys, but that should possibly be
after seeing a reproducer.)
Merhaba, both SDL_image and SDL3 were on the master branch when I posted this. I'm comparing the results of using SDL_LoadBMP and IMG_Load. Considering the rendering code stays the same and I only load an SDL_Surface*
to pass onto my Texture Transfer Buffer, here are the results:
My BMP loading function:
// ...
result = SDL_LoadBMP(fullPath);
if (result == NULL)
{
SDL_Log("Failed to load BMP: %s | %s", SDL_GetError(), fullPath);
return NULL;
}
if (desiredChannels == 4)
{
format = SDL_PIXELFORMAT_ABGR8888;
}
else
{
SDL_assert(!"Unexpected desiredChannels");
SDL_DestroySurface(result);
return NULL;
}
if (result->format != format)
{
SDL_Surface *next = SDL_ConvertSurface(result, format);
SDL_DestroySurface(result);
result = next;
}
return result;
But when I load the png it with SDL_image:
// ...
auto surface = IMG_Load(fullPath);
if (!surface) {
SDL_LogError(SDL_LOG_PRIORITY_CRITICAL, "Error creating texture: %s", SDL_GetError());
}
return surface;
Here is what is drawn on the window:
I thought I was doing something wrong but seeing it work fine with BMP confused me If there was a problem with loading the image data.
Thanks for asking for the reproducer, I found my mistake which was stupid of me. I was using SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM
instead of ``SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM. I expected ABGR to look like
A8B8G8R8` but the SDL3 team went with `B8G8R8A8` instead. Thanks for answering tho, It helped me notice the issue 😄
Merhaba,
Selam !
Thanks for asking for the reproducer, I found my mistake which was stupid of me. I was using
SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM
instead of ``SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM. I expected ABGR to look like
A8B8G8R8` but the SDL3 team went with `B8G8R8A8` instead. Thanks for answering tho, It helped me notice the issue 😄
OK, glad that it's resolved!