SDL problem

This is a discussion on SDL problem within the Game Programming forums, part of the General Programming Boards category; I'm using SDL_Surface for my bitmaps, the thing is i want to rotate and scale my bitmaps, and blit them ...

  1. #1
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377

    SDL problem

    I'm using SDL_Surface for my bitmaps, the thing is i want to rotate and scale my bitmaps, and
    blit them after that. Is there a gl function for this, or should i write an algorithm for it. In case
    so, give me some tips - i need this scaling and rotating to be fast as possible.
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    106
    I don't believe there are built-in functions with SDL that do this.

    BTW, if you can rotate PNGs, you should probably use those. Bitmaps are really freaking huge.

  3. #3
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    I recommend the SDL Graphics Extension (http://www.etek.chalmers.se/~e8cal1/sge/)
    It does scaling/rotation, as well as some other stuff that might be handy

  4. #4
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    but i just want scaling and rotation, not other stuff...
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  5. #5
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    and besides i'm using SDL_Image, so it doesn't matter what i load ( .jpg .bmp .png ... ) it's all SDL_Surface
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  6. #6
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    If you want to do it yourself then read this for scaling:http://scien.stanford.edu/class/psyc...cts/99/emkwok/

    rotation pseudocode:
    Quote Originally Posted by some site :)
    Code:
    float OriginalXPos = 0;
    float OriginalYPos = 0;
    for (long Y = 0; Y < ImageHeight; Y++)
    {
      float CurrentXPos = OriginalXPos;
      float CurrentYPos = OriginalYPos;
      for (long X = 0; X < ImageWidth; X++)
      {
          TargetPixel [Y][X] = Image [CurrentYPos][CurrentXPos];
          CurrentXPos += cos (Angle);
          CurrentYPos += -sin (Angle);
      }
      OriginalXPos += sin (Angle);
      OriginalYPos += cos (Angle);
    }

  7. #7
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    thanks. but this rotation pseudocode isn't the fastest way, i gues...
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  8. #8
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    I can't get cos, sin, (sin) on -1 to work! <math.h> sucks
    can you post an example of using cos, sin, -sin with some library
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  9. #9
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    i get these when i try to use cos(), sin() from <math.h>
    Attached Images Attached Images  
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  10. #10
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Well your problem is that you need to cast whatever you enter into cos or sin to float.
    Example...
    Code:
    #include <math.h>
    int main()
    {
          cos((float)5);
    }
    As far as speed goes it should be fine if you compute sin and cos of Angle outside of the loop.

    The only other consideration is that a rotated picture is going to be bigger than a nonrated one. You have to compensate by calculating how big your rotated surface is going to be. Also, it may be neccesary to set the unused parts of the rotated surface transparent.

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Let me know if you get it to work. I'm trying to do the same thing: http://cboard.cprogramming.com/game-programming/74258-bitmap-rotation.html#post528010

    BTW, it doesn't work if you just rotate each pixel individually.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Code:
    #define PI 3.14159
    #define DEGTORAD(angle)  (float) ( (angle) * (PI) / (180.0f )
    ...
      
    float MYSIN[360];
    float MYCOS[360];
    for (int i=0;i<360;i++)
    {
       MYCOS[i]=cosf(DEGTORAD(i));
       MYSIN[i]=sinf(DEGTORAD(i));
    }
    But this skips a lot of angles. Remember that there are an infinite amount of values between 0.0f and 1.0f. This function will produce some fairly jerky rotations but might work for a 2D game.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with SDL
    By Mirchiss in forum Game Programming
    Replies: 1
    Last Post: 07-16-2006, 01:03 PM
  2. SDL Performance problem
    By cboard_member in forum Game Programming
    Replies: 8
    Last Post: 04-09-2006, 01:23 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  4. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 04:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21