问题
I wonder if someone has any idea if it's possible to use .c or .h images with SDL exported in gimp. I know there is .xpm but I can't somehow enable transparency for .xpm images.
I do know there are some complex ways to render .c/.h files in C, but I'd rather use SDL, since I'm trying to learn it.
Thanks in advance!
回答1:
gimp header export function use it's own format, providing a macro used to uncrunch it, more details here
you can load raw data buffer into a sdl surface using SDL_CreateRGBSurfaceFrom
as you want load pictures into sdl, i can suggest you simply convert pictures files as a C array, not as raw pictures but still as bmp or png,
you can use this tool to convert any binary file to a .h
this will provide you file size as a define and a pointer to the file buffer,
#define dataSize 93722
unsigned char data[dataSize] = {
'B', 'M', 0x1A, 'n', 0x1, 0x0, 0x0, 0x0,
0x0, 0x0, 'z', 0x0, 0x0, 0x0, 'l', 0x0,
...
};
as it's sdl you will need to convert the buffer to a SDL_RWops structure,
SDL_RWops * z = SDL_RWFromMem(data,dataSize);
now for load this structure into a fresh sdl surface you need to use *_RW functions,
if you plain to use classic bmp files, it's directly supported in sdl with SDL_LoadBMP_RW the same thing exist in sdl image for all supported pictures types,
SDL_Surface * titleScreen = SDL_LoadBMP_RW(z,1);
for define the transparent color value of a sdl surface, you can use the SDL_SetColorKey function
SDL_SetColorKey( titleScreen, SDL_SRCCOLORKEY, 10);
if you want a concrete example, check this old source, it's uncrunch & load several bmp pictures into sdl from an in memory rar file,
as raw data or bmp are not crunched your executable size can grow up fast, maybe have a look at upx executable compressor, compressing the whole exe will compress his shipped data too, bitmap or raw will be crunched but still raw in your program
来源:https://stackoverflow.com/questions/21149247/using-c-h-images-exported-with-gimp-in-sdl