SDL Rotation and the Most Unsettling Book Ever


JAGS title screen New title screen. Don’t worry, the cornflower blue is temporary.

I was thinking about using OpenGL to port JAGS over, rather than blitting images using the SDL libraries, and now it looks like I may have to, even after porting all the code I’ve done so far. The reason is that apparently, there’s no good way in SDL to rotate things in real time. I can’t imagine why that is; then again, I have no idea how the SDL rendering engine is written.

Remember that rotations are kind of an important thing in JAGS, for two reasons: I’ve got to rotate the character sprite around to face the mouse, and I’ve also got to rotate projectiles. SDL_Gfx has a function to draw lines, which I hope is reasonably fast, but if I want to add in rockets or other things later then I’d like to rotate those too.

It seems that the only good ways to do real-time rotations are to (1) pre-render all of your rotations using some program, (2) rotate using some library like SDL_GFX that takes your SDL_Surface, copies it, transforms it, and gives that to you (which is reputedly quite slow) or (3) switch to OpenGL and use GlRotate3f (is that correct? I think it is). Right now, I’m trying to implement a combination of (1) and (2); at the beginning of the program, I rotate the surface using SDL_Gfx, store those rotated surfaces in an array an use the nearest degree to what I need.

When I rotate the image every 2 degrees until we get back to 360, this produces fairly good results. Spinning the image around continuously, you can’t even tell that it isn’t rotating every degree. This method makes 180 sprites, each 32x32. Assuming each color takes 8 bits, and throwing in another 8 for the alpha channel, thats 32 bits or 4 bytes for each pixel; 43232*180 = 11520 bytes or .703 megabytes. Looking at the little test program I wrote to see exactly how much it uses, I was actually off by a factor of 2: memory usage in Task Manager jumps from 3428kb to 4848kb, a difference of 1.42mb. I guess the image is actually 8 bytes per pixel? I don’t know enough about images to tell for sure.

Sample JAGS view New display from in-game. Collision, server joining, and chat are all working, but projectiles and rotation are in the works. The wall/floor textures are here to stay until I find someone to draw better ones.

To be honest, this is not, at all, a lot of memory. A typical 3D shooter will have textures with resolutions of 4096x4096 (or larger), for a total of 64 megabytes of texture data (still assuming 4 bytes per pixel). There are most likely ways to reduce this exponentially that I don’t know anything about (I just made a test file with a bunch of squigglies, and it’s ~3mb) but duplicate that many times, for different textures, draw that all over the place, and you get a **ton **more texture data than my dinky little 2D shooter, even with the performance hit brought about by duplicating and rotating my player over and over again.

I am still not sure if I am willing to let go of these 11-odd kilobytes. They are quite dear to me, in fact. I want this game to be something that can be played on old, old systems. If I write the engine badly, then everything built on top of it will be bad as well. On the other hand, I’m not sure if I’m willing to risk the time investment needed to port all of this to yet another rendering engine. It would be a lot of work for not a lot of profit.

I’ve thought on it and, well, I haven’t come to a conclusion yet. The weeks leading up to finals week have been ridiculously hectic. While not as bad as last week, this week I’ve got yet another 3 projects due on about the same day. So, we’ll see.

In other news, I’ve been reading John Dies at the End. Do not read it. It is the most unsettling book I have ever read. You see the background to the website in the link? That is the cover for the book. It is not scary in the direct, in your face kind of way. It is not a horror movie. It is the kind of book that makes you think you’re seeing things out of the corner of your eyes, and that maybe that isn’t ketchup, maybe it’s blood. Then you shake your head and think no, that couldn’t go on in my tiny college town, just couldn’t. But it’s always in the back of your mind. It is well written, though.

After that last paragraph, if you still want to read it, you’re just plain insane. Best of luck to you.