Archived

This topic is now archived and is closed to further replies.

Rotating a Bitmap

This topic is 5600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Well here I am, trying to rotate a bitmap . I remembered seeing a library called "rotozoom" on the main SDL page, but it only works with Linux (supposedly). So what am I supposed to do? Write my own function? If so, how? Is there a function in SDL that I can use (I don''t see any in the Doc Project). I feel pretty wierd asking a question like this, newbyish? I''m used to glRotatef(), so I''m pretty stumped here. Thanks for any responses. ------------------------------ Simple DirectMedia Layer:
Main Site - (www.libsdl.org) Cone3D Tutorials- (cone3D.gamedev.net) GameDev.net''s Tutorials - (Here)
OpenGL:
Main Site - (www.opengl.org) NeHe Tutorials - (nehe.gamedev.net) Online Books - (Red Book) (Blue Book)

Share on other sites
*bump*

It's really bothering me. Really .

Edited by - Drizzt DoUrden on February 19, 2002 6:55:55 PM

Share on other sites
Check out SDL_gfx

"Don''t be afraid to dream, for out of such fragile things come miracles."

Share on other sites
Hey,
I don''t remember where it is, but there''s an article on the net (not GameDev) devoted to software rotation of images.

It''s not particularly fun, nor is it particularly fast; but if you must do it, I suggest looking for it.

--Nairb

Share on other sites
quote:
Original post by Redleaf
Check out SDL_gfx

Yeah Readleaf - that''s what I''m using. Drizzt, this library (SDL_gfx) contains a rotozoomSurface() function that you can use in Windows - I''ve used it sucessfully. It''s nothing complex, but email me if you run into any problems. Just be sure to #include "sdl_rotozoom.h" as well as place the sdl_rotozoom.c in your project so you don''t get nasty link errors

_________________________________________________________________

Drew Sikora
A.K.A. Gaiiden

ICQ #: 70449988
AOLIM: DarkPylat

Staff Member, GDNet
Public Relations, Game Institute

3-time Contributing author, Game Design Methods , Charles River Media (coming April/May 2002)
Online column - Design Corner at Pixelate

NJ IGDA Chapter - NJ developers unite!! [Chapter Home | Chapter Forum]

Share on other sites
for (x,y) = pixel on the target bitmap T   figure out (x0,y0) whence in the source bitmap S   the pixel T(x,y) comes from   ( e.g. x0 = cos(-angle)*x,           y0 = sin(-angle)*y,      if you arer centered at (0,0) )   plot the pixel at T(x,y) with the color from S(x0,y0),   possibly with supersampling    (e.g. averaging the neighbouring colors)

Share on other sites
Maybe it is a rare deficiency of SDL, the lack of hardware scaling and rotation.
Well, who knows, maybe it will be included in a future version.

Share on other sites
quote:
Original post by Gaiiden
Yeah Readleaf - that's what I'm using. Drizzt, this library (SDL_gfx) contains a rotozoomSurface() function that you can use in Windows - I've used it sucessfully. It's nothing complex, but email me if you run into any problems. Just be sure to #include "sdl_rotozoom.h" as well as place the sdl_rotozoom.c in your project so you don't get nasty link errors

The problem here is that it still uses SDL_rotozoom. SDL_gfx just has SDL_rotozoom as part of it, and SDL_rotozoom only works for Linux. Or is the rotozoom in SDL_gfx completely different?

[EDIT] - looked at SDL_rotozoom.c:
They include "windows.h" in SDL_rotozoom.c. This means that the rotation will only work in windows correct?
[/EDIT]

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net's Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)

Edited by - Drizzt DoUrden on February 20, 2002 3:33:31 PM

Share on other sites
It is not a deficiency of sdl, they focus more on platform independence then on feature richness. They don''t claim to be a complete game engine.....

BTW, the library SGE (SDL Graphics Extention) claims to do rotation and transformation, but i haven''t tried it.....

Share on other sites
quote:
Original post by Drizzt DoUrden
The problem here is that it still uses SDL_rotozoom. SDL_gfx just has SDL_rotozoom as part of it, and SDL_rotozoom only works for Linux. Or is the rotozoom in SDL_gfx completely different?

[EDIT] - looked at SDL_rotozoom.c:
They include "windows.h" in SDL_rotozoom.c. This means that the rotation will only work in windows correct?
[/EDIT]

Yeah, but you''ll notice that they encase the windows include in an #ifdef directive, so that only if the code is being used on a Win32 platform is the header included. Will you just go ahead and use it already?? It works! Yeesh, hee hee

Share on other sites
Heh. I would but I got side-tracked by my Pong clone.. it''s slow as \$h1t on computers that aren''t as fast as mine, so I need to figure out what''s making it so slow.

I''m assuming it''s the fact that I''m blitting the whole bitmap instead of only part of it (because blitting is usually what decreases the speed...), because I can''t really comprehend Cone3D''s third tutorial.

Once I figure that out or get so frustrated I need to go hug a tree (In a nice way of putting it ), I''ll work with the rotozoom stuff.

Thanks for the help!

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)

Share on other sites
Consider me frustrated!

I went and cut everything from my game loop, don''t ask why; it''s a long story. Then I went to Build my app and the computer froze. I restarted the computer and nothing is left in my loop. Tell me that''s not frustrating? All of the important/hard code was in there...

Anyway, if I let it get to me I''ll probably get depressed. So I''ll just go work on my rotating ship program instead .

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)

Share on other sites
a rotozoom is a hybrid zoomer/rotator .. it''s fast because it skips pixels in resizing. So do not expect nice anti-alias rotations =)
I have not used SDL.. but I do know that a rotozoom does.

Share on other sites
*sigh*

Too many problems. First of all, my code is sorta like this:

  #define PI 3.14159#define MOVEMENT 2.0float radian;float rotation = 90.0;

And on key press up(accellerate)
  radian = ((PI * rotation) / 180.0);destShip.x = destShip.x + (MOVEMENT * (cosf(radian)));destShip.y = destShip.y + (MOVEMENT * (sinf(radian)));

destShip.x and destShip.y are doubles first of all. I don't know what the effect would be converting them to a float.

Secondly, I have math.h included. I don't have problem with this librar untill I add the SDL_rotozoom.c to my project, and include SDL_rotozoom.h. What's the problem? I get this error:

quote:

d:\program files\microsoft visual studio\vc98\include\math.h(514) : error C2894: templates cannot be declared to have 'C' linkage

And when I click it, it shows me this: (In math.h)

  template inline _Ty _Pow_int(_Ty _X, int _Y) {unsigned int _N; if (_Y >= 0) _N = _Y; else _N = -_Y; for (_Ty _Z = _Ty(1); ; _X *= _X) {if ((_N & 1) != 0) _Z *= _X; if ((_N >>= 1) == 0) return (_Y < 0 ? _Ty(1) / _Z : _Z); }}

If that was any more confusing.... Anyway.

Do you know what's going on?

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net's Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)

Edited by - Drizzt DoUrden on February 20, 2002 9:39:18 PM

Edited by - Drizzt DoUrden on February 20, 2002 9:40:26 PM

Share on other sites
quote:
Original post by smilydon
It is not a deficiency of sdl, they focus more on platform independence then on feature richness. They don''t claim to be a complete game engine.....

BTW, the library SGE (SDL Graphics Extention) claims to do rotation and transformation, but i haven''t tried it.....

It''s a weak argument in favor of a.. lack of feature. Did you ever heard of hardware emulation layer ?
If they implement Hardware Scaling and rotation and if your video board has the capability to do it, it will do it. If not, you still can have scaling and rotation but via software rendering.
So having that feature doesn''t go against hardware independency. If it''s present it is a real bonus that could exploit the possibility of the hardware.
Another detail, SDL is NOT a game engine, it is an API the same as DirectX.
Allegro is a game engine and every game engine uses one of the various API, why reinvent the wheel unless you want to program in DOS

Share on other sites
quote:
Original post by GoofProg
a rotozoom is a hybrid zoomer/rotator .. it''s fast because it skips pixels in resizing. So do not expect nice anti-alias rotations =)

Actually this rotozoom function has a flag setting for SMOOTHING_ON or SMOOTHING_OFF. I dunno exactly how it implements this, but there it is. Of course it''s a lot slower and so I don''t use it much

And Drizzt, your problem sounds familiar. I think that happened to me and I actually had to modify the rotozoom.h header. Let me dig around and see if I can''t remember anything that''ll help

Share on other sites
I still haven''t been able to figure anything out with it. I looked into the .h to see if I recognized anything I should change, but I''m just an intermediate C++ programmer with little expierience I''m pretty sure you are a better coder than me, Gaiiden. Have you been able to remember what you needed to change?

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)

Share on other sites
when I clicked on it, it brought me somewhere in rotozoom.h or rotozoom.c.... I really can''t remember exactly.

Share on other sites
http://cone3d.gamedev.net/files/sdlrotozoom-vc6.zip <- extend this for your own needs...

---
cone3d
http://cone3d.gamedev.net
Multitasking - screwing up several things at once.

Edited by - cone3d on February 22, 2002 8:20:45 AM

Share on other sites
Drizzt, the penguin with the 100% sign on the SDL libraries page before the SDL_rotozoom library doesn''t mean that it won''t work on other systems. I think that is the system the author tested it on and reported that it works on it.

quote:
... and cut everything from my game loop ...

/* use block comments next time */

---
cone3d
http://cone3d.gamedev.net
Multitasking - screwing up several things at once.

Share on other sites
quote:
Original post by cone3d
http://cone3d.gamedev.net/files/sdlrotozoom-vc6.zip <- extend this for your own needs...

You''re awsome! Thanks alot.

quote:

/* use block comments next time */

I had already used block comments and I was too lazy to go change them. *sigh* I''ve learned my lesson.

So far this library is cool.. I had to modify the rotation function (a little bit..) to get rid of the zooming. Now it works quite well.

I should have a working version of the game in a few days.

Thanks for all the help!

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)

Share on other sites
quote:
Original post by Drizzt DoUrden
You''re awsome! Thanks alot.

hehe :D

quote:

I had already used block comments and I was too lazy to go change them. *sigh* I''ve learned my lesson.

heh. oh well...

quote:

So far this library is cool.. I had to modify the rotation function (a little bit..) to get rid of the zooming. Now it works quite well.

I should have a working version of the game in a few days.

that''s nice
quote:

Thanks for all the help!

u''re welcome

---
cone3d
http://cone3d.gamedev.net
Multitasking - screwing up several things at once.

Share on other sites
@Drizzt DoUrden
although im a bit late in this thread here, i gotta say i solved ur problem: u get the failure in the maths include if u use the stdafx.h AND the SDL_rotozoom.h at the same time. i wrote everything i needed in the rotozoom.h, and now it works fine.

• Forum Statistics

• Total Topics
628645
• Total Posts
2984020

• 9
• 9
• 10
• 21
• 20