Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling sprites in SDL

How can i scale sprites in SDL?

like image 523
kmaxeg Avatar asked Feb 15 '10 19:02

kmaxeg


2 Answers

SDL doesn't provide scaling functionality directly, but there's an additional library called SDL_gfx which provides rotation and zooming capabilities. There's also another library called Sprig which provides similar features.

like image 101
Kaleb Brasee Avatar answered Nov 10 '22 17:11

Kaleb Brasee


You can do scaling if you are getting sprites from a texture with SDL_RenderCopy() but i cannot guarantee you antialiasing.

With function SDL_RenderCopy() you pass 4 params:

  • a pointer to a renderer (where you are going to renderize).
  • a pointer to a texture (where you are going to get the sprite).
  • pointer to source rect(the area and position where you get the sprite on the texture).
  • and pointer to dest rect(the area and position on the renderer you are going to draw).

You should only modify your dest rect like for example, if you are going to render an image 300 x 300 and you want it scaled, your dest rect should be like 150 x 150 or 72 x 72 or whatever value you wanted to scale.

like image 5
Ibrahim CS Avatar answered Nov 10 '22 19:11

Ibrahim CS