PDA

View Full Version : SDL rotate/scale


Savant
07-26-2005, 11:11 AM
I searched but couldn't find anything here, which surprised me, so I figured I'd ask.

I was wondering how you SDL guru's out there handle scaling/rotating when drawing graphics in your games. Or do you?

Gnatinator
07-26-2005, 11:29 AM
I dont really use SDL all that much, but iirc, rotation isnt supported and you will need to do it manually with multiple sprites.

You should probably do it this way anyway. Software rotation (without some kind of filtering at least) looks dirty by todays standards.

1EyedJack
07-26-2005, 11:30 AM
You could perhaps take a look at this library:

http://www.ferzkopp.net/~aschiffler/Software/SDL_gfx-2.0/

there are functions for rotation, zoom...

Jesse Aldridge
07-26-2005, 11:33 AM
I beleive this is what you're looking for: SDL_gfx lib (http://www.ferzkopp.net/~aschiffler/Software/SDL_gfx-2.0/) . I've used it with success - just drop the rotozoom files into your project. The file is well commented so the functions are easy to use.

Note that this is software rotation - if you need to rotate big sprites or a lot of sprites, I've heard that using OpenGL with SDL is the best option.

Jesse Aldridge
07-26-2005, 11:37 AM
Software rotation (without some kind of filtering at least) looks dirty by todays standards.

The rotation call for SDL_Gfx has a parameter to turn smoothing on or off.

Sharkbait
07-27-2005, 12:39 AM
My own 'game engine' uses pure SDL for software rendering and OpenGL over SDL for hardware rendering (currently in the works). For scaling and/or rotation I have my own code derived from SDL_gfx. For the hardware rendering mode, I simply use OpenGL's texturing functionality.

Interpolated software scaling and rotation is acceptable for small sprites but I would definitely avoid it for large sprites. So far I did not have to deal with heavy rotation processing, but if I had, I would either pre-generate the rotated images or implement a caching system with a granularity parameter to trade off memory usage vs accuracy of rotation.

Robert Cummings
07-27-2005, 01:57 AM
How is alpha blending? Are there additive or multiply blend modes?

Sharkbait
07-27-2005, 05:53 AM
Once again, it's "Roll-Your-Own" territory, at least as far as I am aware! Well.. the hard bit is getting interpolated scaling/rotation to work, after that, additive and multiplicative blending is relatively easy to implement.

Also in terms of normal (1 - source alpha) blending in SDL you either have the choice of applying an overall alpha component to an RGB image or use the alpha channel of an RGBA image.. you cannot do both! I went around this limitation by modulating the alpha channel of RGBA images with an overall alpha value before rendering (storing the original alpha channel for subsequent blits). This technique is obviously quite CPU intensive so I try to keep its use to a minimum. With OpenGL it's a completely different story since you can apply both an RGBA texture and a modulating RGBA colour via glColor*(...).

soniCron
07-27-2005, 11:20 AM
With OpenGL it's a completely different story since you can apply both an RGBA texture and a modulating RGBA colour via glColor*(...). And just a note of compatability: the ATI Rage cards do not allow alpha modulation. Not that many folks will target such a card, but they were very popular among OEMs. Just a heads up! :)

Savant
07-27-2005, 11:54 AM
Oy vey...

OK, thanks everyone.