[SDL] RotoZoom is great, but...

Torsten Giebl wizard at syntheticsw.com
Sat Sep 2 07:39:58 PDT 2006


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.


CU





More information about the SDL mailing list