Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to scale an SDL Surface without clipping?

Tags:

opengl

sdl

what is the proper way to scale an SDL Surface? I found one explanation online but it required redrawing the Surface pixel by pixel. It seems like there should be some way of doing this natively through SDL rather than redrawing the image like that. I haven't been able to find anything in the SDL documentation that covers this. I am able to resize surfaces without any problem by modifying the surfaces width and height, but the resulting surface is clipped.

like image 299
jamesmillerio Avatar asked Nov 30 '08 05:11

jamesmillerio


2 Answers

I know this answer is way too late to assist the person who asked it, but I decided to write this to help anyone who stumbles upon this question. In SDL 2.0 You can use the SDL_BlitScaled() function to scale a surface into a targeted SDL_Rect. There's a tutorial by LazyFoo which describes this, or check out this documentation.

like image 195
Justin Stephens Avatar answered Nov 03 '22 09:11

Justin Stephens


SDL doesn't support scaled blitting. According to the documentation of SDL_BlitSurface:

Note: the SDL blitter does not (yet) have the capability of scaling the blitted surfaces up or down like it is the case with other more sophisticated blitting mechanisms. You have to figure something out for yourself if you want to scale images (e.g. use SDL_gfx).

You could find SDL_gfx here. Writing your own blitting function isn't that bad, it might be a fun and useful learning experiment (though you'd be reinventing the wheel). Using OpenGL is also an option, as stuff like scaling and rotating could be done in a single function call.

like image 23
Firas Assaad Avatar answered Nov 03 '22 08:11

Firas Assaad