SDL_RotateSurface(3)

πŸ“¦
version 3.4.18 Β· 5 versions
, in fedora 43, fedora 44

πŸ’« SDL_RotateSurface(3) β€” the SDL3 FUNCTIONS glow-up

okay bestie, welcome to the SDL_RotateSurface page, part of the SDL3 FUNCTIONS lineup πŸ’…


✨ NAME ✨

SDL_RotateSurface β€” hands you back a copy of a surface, rotated clockwise by some number of degrees. yes, a copy. we don't touch the original, we're not monsters πŸŽ€


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_surface.h>

SDL_Surface * SDL_RotateSurface(SDL_Surface *surface, float angle);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the rotation angle? it can be negative and that's not a bug, that's on purpose β€” negative = counter-clockwise. we love options πŸ’–

When the rotation isn't a multiple of 90 degrees, the resulting surface is bigger than the original. no cap. and the background gets filled in with the colorkey, if there is one available, or with RGBA 255/255/255/0 if there isn't. that's just how she pads 🫢

now here's the part that's giving ✨spicy math✨: if surface has the SDL_PROP_SURFACE_ROTATION_FLOAT property set on it, the new copy will have the adjusted value set. like β€” if the rotation property is 90 and angle was 30, the new surface will have a property value of 60. (that is: to be upright vs gravity, this surface needs to rotate 60 more degrees.) love that for her 😌

⚠️ but bestie, note this: further rotations on the new surface in this example will produce unexpected results, since the image will have resized and padded to accommodate the not-90 degree angle. like, she's changed shape. she's not who she was. πŸ™ˆ

🌈 FUNCTION PARAMETERS 🌈

  • surface β€” the surface to rotate. that's the one getting the glow-up.
  • angle β€” the rotation angle, in degrees. yes, degrees. not radians. we keep it simple here πŸ“

πŸ’œ RETURN VALUE πŸ’œ

Returns a rotated copy of the surface πŸŽ‰ or NULL on failure 😭 β€” in which case, call SDL_GetError() for more information. she'll tell you what went wrong.


🧚 THREAD SAFETY 🧚

This function can be called on different threads with different surfaces. so like, parallel vibes, no drama, as long as everybody's got their own surface πŸ‘‘


⭐ AVAILABILITY ⭐

This function is available since SDL 3.4.0. not that old, but already iconic.


and that's the whole page, bestie πŸ’– huge thank you to Simple Directmedia Layer for shipping this one in SDL 3.4.18 β€” go rotate something pretty, you've got this πŸŽ€βœ¨

πŸ“¦ where this page comes from