[SDL] RotoZoom is great, but...

SlntHero at aol.com SlntHero at aol.com
Sat Sep 2 07:45:24 PDT 2006

I need on-the-fly BMP rotation and scaling, the memory requirements to  store 
pre-processed rotations/scaling is TOO LARGE.
wizard at syntheticsw.com writes:
The problem in your case maybe that rotozoom always creates
new Surfaces  and you never free them.

- How do I FREE an SDL surface? (probably stupid question, but I do not  know 
the answer)
_SLNTHERO at AOL.com_ (mailto:SLNTHERO at AOL.com) 
_www.SilentHeroProductions.com_ (http://www.SilentHeroProductions.com) 
In a message dated 9/2/2006 10:41:32 A.M. Eastern Standard Time,  
wizard at syntheticsw.com writes:

Hello  !

> void Visuals::DisplayBMPonScreenBufferRotoZoom(Sint8  spriteNumber, Sint16
>  xScreenPos, Sint16 yScreenPos, double  angle, double zoom) {
> SDL_Rect   destinationRectangle;
> destinationRectangle.x =  xScreenPos; destinationRectangle.y  = yScreenPos;
>  SDL_Surface *temp = SpriteBMP[spriteNumber];
> SDL_Surface  *temp2  = rotozoomSurface(temp, angle, zoom, 1);
>  destinationRectangle.x -= (temp2->w /  2); destinationRectangle.y  -=
> (temp2->h / 2);
> SDL_BlitSurface(temp2,  NULL, Screen,  &destinationRectangle);
>  }
> Hi the above Class function  centers properly the new scaled and/or
> rotated BMP  100%.
> Problem now is that is crashes after a set  period of time
> (Access Violation error)

Rotozoom is  normally not optimized for only the fly
blitting. It works okay will small  surfaces, but when
you have the memory it is better to rotate all the  surfaces
before you need them in the init routine.

Another + for  this is you can use SDL_DisplayFormat
to get the fastest possible blitting  and you can use the RLE Flag.

I would do it that way :

For  example SDL_Surface *mainShipSprite [360];
Load it with all rotated  surfaces with degrees from 0-360.
If you need less, you can just use the  angles you need.
Then when blitting do SDL_Blit ... mainShipSprite [angle %  360] ...

That way you can directly blit with the wanted  angle.

The problem in your case maybe that rotozoom always  creates
new Surfaces and you never free  them.


SDL  mailing  list
SDL at libsdl.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060902/497481b7/attachment-0008.htm>

More information about the SDL mailing list