[SDL] Stretching

Eugen Kimmerstorfer k2043e8 at jk.uni-linz.ac.at
Wed Aug 25 01:08:45 PDT 1999


A quite easy way to stretch a bitmap is to use the Hermes library
(http://hermes.terminal.at).
Here is some sample code (without error checking):

//**********************************
...
HermesHandle handle;
HermesFormat *s, *d;
SDL_Surface *source, *dest;

...
// load a bitmap into *source or something else
// *dest could be just the screen background
...

Hermes_Init();
handle = Hermes_ConverterInstance(HERMES_CONVERT_NORMAL);
s = Hermes_FormatNew(source->format->BitsPerPixel,
	source->format->Rmask,
	source->format->Gmask,
	source->format->Bmask,
	source->format->Amask, 0);
d = Hermes_Format_New(dest->format->BitsPerPixel,
	dest->format->Rmask,
	dest->format->Gmask,
	dest->format->Bmask,
	dest->format->Amask, 0);
Hermes_ConverterRequest(handle, s, d);
Hermes_ConverterCopy(handle,
	source->pixels,
	sourceX,
	sourceY,
	sourceWidth,
	sourceHeight,
	source->pitch,
	dest->pixels,
	destX,
	destY,
	destWidth,
	destHeight,
	dest->pitch);
SDL_UpdateRect(dest, destX, destY, destWidth, destHeight);
Hermes_ConverterReturn(handle);
Hermes_Done();

//***************************

If destWidth and destHeight is the same like sourceWidth and
sourceHeight,
just a normal blitting is done. Otherwise Hermes stretches the "bitmap"
to
the size of the destination. Works fine. I just had some problems with
24 bpp (e.g. loading a BMP-File to source). But a call to
SDL_DisplayFormat(...)
solved the problem.

Hope, I could help you.

Eugen

------------------------
Ryan Wahle wrote:
> 
> Hi,
> 
> Does anyone here know how sdl stores a bitmap in memory? the reason I ask
> is because i want to impletment stretching of bitmaps for my game, and was
> just wondering how I could get the sdl_surface and mess around with the
> bitmap data so i can stretch it.
> 
> thanks. see ya



More information about the SDL mailing list