Open DanielGibson opened 7 years ago
First let me thank you for writing such a detailed and easy to understand post.
I know this is an old post but I was hoping you could provide some insight. I'm basically using the code from your post as-is but I noticed the colors and alpha were off. The endian is big, and the red channel is accurate, but somehow the other channels are getting mixed up. Here's a screenshot with the result on the left and the original image in GIMP on the right: .
I tried to rearrange the masks but no matter how I change them it will cause the image to fail to load with SDL giving the error "Unknown pixel format". The thing is I don't think it's SDL, I think maybe there's something screwy with how GIMP is emitting the array - specifically the color channels, but I can't quite figure it out. There are few code samples I can find, and all of them seem to handle things basically the same way, so I have a suspicion the GIMP exporter is actually broken.
My GIMP version is 2.10.32, and I'm using SDL2 version 2.24.0
Here's the exported image data if you or anyone wants to try it themselves:
the endian is big
You're using a big endian CPU? Seems possible that Gimp has a bug in it's C exporter on big endian.
Also possible that my code is somehow incorrect, I don't have any big endian machines, but you said that you tried different masks and it still didn't work..
You could try converting the image with my ImgToC tool instead of gimp, maybe that works better? https://github.com/DanielGibson/Snippets/blob/master/ImgToC.c
Ah, sorry for not updating - I got it to work but I used image magick (I'll grab/extract what I did if you want to know). I can tell you off hand the command I used to convert was like convert test.png -define h:format=RGBA test.h
- the important part in that command being the -define h:format=RGBA
- you can just define the bit orders/formats somewhat arbitrarily that way (otherwise you get a non-alpha PBM image if I remember correctly).
I think the endian-ism may actually be the GPU or some abstraction with GL - the CPU in this particular case is an Intel x86-64 which is little endian but I actually out of curiosity tied it on my Raspberry Pi 4 and the result was somehow the same, so I think it's some sort of GL abstraction or maybe even some misconfiguration in how Ubuntu/Debian is compiling their SDL2 packages.
The thing with the masks is I think SDL just only supports a few different mask patterns. I found some would run even if they were incorrect but others would give the "Unknown pixel format error." and the pattern that I would in fact need to support that GIMP export just happens to be unsupported.
Comments for https://blog.gibson.sh/2015/04/13/how-to-integrate-your-sdl2-window-icon-or-any-image-into-your-executable/