If you have an SDL_Surface which can be used as a reference, you can simply
use its properties. Here is some pseudo-code :
Unfortunatly I only have my Display Surface, but that's not what I want to
use, because the images are used as OpenGL textures. To make it simple I just
want to load the image and store it in RGBA format (or RGB format, but that’s
a trivial change). I can’t seem to find a way to create a pixel format for
RGBA with a function call, so I’ve used the following:
SDL_Surface *image, *dst_image;
SDL_PixelFormat dst_format = {
NULL,
24,
3,
0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF, // Color masks (RGBA)
0, 0, 0, 0, // Color loss (RGBA)
24, 16, 8, 0, // Color shift (RGBA)
0,
0
};
debug("Loading BMP texture [%s]\n", filename);
if(!(image = SDL_LoadBMP(filename))) {
debug("Could not open BMP image [%s]\n", filename);
return false;
}
if(!(dst_image = SDL_ConvertSurface(image, &dst_format, 0))) {
debug("Could not convert BMP surface to desired format\n");
SDL_FreeSurface(image);
return false;
}
...
To convert the texture to an RGB image. However the colors of the newly
created image is swapped (what was blue is now red) so I figure my
PixelFormat is wrong. Also I can’t figure out which flags to specify for the
conversion, I guess it doesn’t matter actually, so I just send 0 (it works
but colors are wrong, which I guess the flags has nothing to do with)
Am I doing something wrong? Or have I missed the point completely? :)
SDL_Surface * ref;
SDL_Surface * bmp;
SDL_Surface * background;
bmp = SDL_LoadBMP (filename);
background = SDL_ConvertSurface (bmp, ref->format, ref->flags);
SDL_FreeSurface (bmp);
bmp = 0;
Thanks for the example, unfortunatly I don't have any reference format :-/
NB: If you want to use the Video Surface as a reference surface (i.e if you
want the pixel format to be the same as the display frame buffer for fast
blitting) then you can use SDL_DisplayFormat (or SDL_DisplayFormatAlpha)
instead of SDL_ConverSurface. It is some kind of “call SDL_ConvertSurface
and fill in the blanks in the parameters list”
I hope this was clear as I am not a native english speaker…
Neither am I :)
Thanks for your help.On Thursday 10 June 2004 13:49, Michel Nolard wrote:
–
Simon Ejsing, Systemudvikler
esoft ApS, http://www.esoft.dk
Skibhusvej 52C, DK-5000 Odense C.
Tlf: 70 222 466, Fax: 63 122 466