[SDL] RotoZoom is great, but...
David Olofson
david at olofson.net
Sat Sep 2 10:02:21 PDT 2006
On Saturday 02 September 2006 18:39, SlntHero at aol.com wrote:
[...]
> 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, 0);
I don't think you're supposed to mess directly with the clip rects...
(Use SDL_SetClipRect().) Also, the clip rect is automatically set to
the full size of a surface when it's created, so unless you want to
restrict rendering to a smaller rectangle, you don't need to touch
this at all.
Either way, clip_rect is for blits *to* a surface. That is, if you
want to clip when rendering to the display, you should use
SDL_SetClipRect() on the *display* surface.
> temp->clip_rect.x = 0;
> temp->clip_rect.y = 0;
> temp->clip_rect.w = 640;
> temp->clip_rect.h = 480;
>
> temp2->clip_rect.x = 0;
> temp2->clip_rect.y = 0;
> temp2->clip_rect.w = 640;
> temp2->clip_rect.h = 480;
No need for these two as SDL_BlitSurface() ignores the size of the
destination rectangle anyway.
Only x and y are used. Also note that SDL_BlitSurface() will overwrite
destinationRectangle with the resulting rect after clipping! This is
important to keep in mind if you're doing multiple blits in sequence,
reusing variables and stuff.
> destinationRectangle.w = temp2->w;
> destinationRectangle.h = temp2->h;
>
> destinationRectangle.x -= (temp2->w / 2);
> destinationRectangle.y -= (temp2->h / 2);
>
> SDL_BlitSurface(temp2, NULL, Screen, &destinationRectangle);
>
> // SDL_FreeSurface(temp);
> // SDL_FreeSurface(temp2);
You should still free temp2, I think! (rotozoomSurface() creates a new
surface, right?)
Didn't spot any obvious reason for crashing, though. What does the
debugger say? Where exactly does the crash happen?
//David Olofson - Programmer, Composer, Open Source Advocate
.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
'-- http://www.reologica.se - Rheology instrumentation --'
More information about the SDL
mailing list