[SDL] Stretching

Stuart Anderson stuart at linuxfreak.com
Tue Aug 24 16:54:31 PDT 1999


John Garrison wrote:
> 
> 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

you can scale-blit using somthing like this, untested, just-written code

(For 16bit)

void scale_blit( SDL_Surface *src, SDL_Surface *dst, float xscl, float
yscl ) {
	Uint16 *srcptr = (Uint16 *)src->pixels;
	Uint16 *dstptr = (Uint16 *)dst->pixels;

	int srcX=0, srcY=0;

	for( int y=0; y < dst->h; y++ ) {
		for( int x=0; x < dst->w; x++ ) {
			*dstptr = *srcptr;
			dstptr++;
			if( (int)(x / xscl) > srcX ) {
				srcptr+=(int)(x/xscl) - srcX;
				srcX = (int)(x / xscl );
			}
		}
		if( (int)(y / yscl) > srcY ) {
			srcptr+= ((int)(y / yscl) - srcY)*src->w - srcX;
			srcY = (int)(y / yscl);
		}
	}
}



More information about the SDL mailing list