本文介绍了在使用SDL与GIMP出口.C / .H图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有人有任何想法,如果它可以使用.C或.H图像与SDL在GIMP出口。我知道有.xpm但我不能以某种方式使透明度.xpm图像。

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.

我知道有一些复杂的方式来呈现的.c / .h文件在C,但我宁愿使用SDL,因为我想学习一下。

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.

在此先感谢!

推荐答案

瘸子头导出功能,使用它自己的格式,提供用于uncrunch它一个宏,详细信息here

gimp header export function use it's own format, providing a macro used to uncrunch it, more details here

您可以使用原始数据缓存加载到SDL表面

you can load raw data buffer into a sdl surface using SDL_CreateRGBSurfaceFrom

只要你想加载图片到SDL,我可以建议你简单地转换图片文件为C数组,而不是作为原始图片,但仍BMP或PNG,

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,

您可以使用任何二进制文件转换为.H

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,
...
};

因为它是SDL您将需要缓冲区转换为结构,

SDL_RWops * z = SDL_RWFromMem(data,dataSize);

现在负载这种结构成你需要使用* _RW功能的新的SDL表面,

now for load this structure into a fresh sdl surface you need to use *_RW functions,

如果您简单的使用经典的BMP文件,它的直接支持SDL与
同样的事情在 SDL图片对于所有支持的图片类型,

if you plain to use classic bmp files, it's directly supported in sdl with SDL_LoadBMP_RWthe same thing exist in sdl image for all supported pictures types,

SDL_Surface * titleScreen = SDL_LoadBMP_RW(z,1);

有关定义SDL表面的透明色值,可以使用功能。

for define the transparent color value of a sdl surface, you can use the SDL_SetColorKey function

SDL_SetColorKey( titleScreen, SDL_SRCCOLORKEY, 10);

如果你想有一个具体的例子,,这是uncrunch&安培;从加载多个BMP图片到SDL在内存RAR文件,

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,

作为原始数据或BMP不会嘎吱嘎吱的可执行文件的大小可以快速成长起来,也许看看的可执行COM pressor,
COM pressing整个exe将COM preSS他出货数据量太大,位图或生将嘎吱作响,但在你的程序还是生

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

这篇关于在使用SDL与GIMP出口.C / .H图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 16:47