Thread: How do I rotate images 90 degrees in SDL?

  1. #1
    Registered User
    Join Date
    Oct 2013
    I forgot

    How do I rotate images 90 degrees in SDL?

    I'm well aware SDL has no standard libraries for rotations, but I didn't want to use a third party library to do this since in this case all I want is a 90 degree rotation. From what I've read, SDL_gtx( spelling may be wrong ) is slow, and I don't want to have to download it and set it up anyways. I've also looked at OpenGL, but I don't want to have to write 100 lines of obfuscated code just to be able to have complete rotation control when I only need 90 degree turns. That being said, I coud use a vertical picture and a horizontal picture, but that would take too much memory space if I needed to rotate multiple pictures 90 degrees. Also, I don't want copyright infringement of LazyFoo's tutorial since I'm making a game program for a state competition. Although I am using his functions right now, and they are heavily modified, I think that they might be a violation. That is why I came here to ask how I could do this with a single image. I'm guessing I would have to somehow inverse the x-axis and the y-axis, but I don't know how to do this without cropping some part of the image. If anyone can help with this, it would be greatly appreciated.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    I do not know SDL but the easiest way to rotate any image in OGL or D3D is to create a quadrilateral from two triangles, texture it with your chosen image and rotate it via matrices just as you would any other primitive.

  3. #3
    Registered User
    Join Date
    Nov 2012
    If you're using SDL in my opinion you should also be using the other SDL_* libraries, so I think there's no excuse for not installing these along with it: SDL_gfx, SDL_ttf and SDL_image. SDL_gfx has rotation abilities. If it's slow then use openGL instead because then it will use hardware rendering. But really if you rotate a surface 90 degrees I can't imagine this is slow in software. If you need to rotate often you can probably cache the result somewhere to optimize things. E.g. have 4 versions of your surface, one for each possible 90 degree rotation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-04-2012, 07:28 AM
  2. Making Servo rotate 180 degrees
    By streamline in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2008, 11:19 AM
  3. rotate screen by XX degrees?
    By Dag_ in forum C++ Programming
    Replies: 2
    Last Post: 06-08-2005, 05:47 AM
  4. How do I rotate a matrix 45 degrees?
    By caduardo21 in forum C Programming
    Replies: 2
    Last Post: 06-06-2005, 01:19 AM
  5. sin() and cos() that use degrees
    By dwks in forum C Programming
    Replies: 3
    Last Post: 05-14-2005, 04:29 PM