🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Rotate bitmap with directdraw

Started by
13 comments, last by GameDev.net 24 years, 6 months ago
As far as I know, there's no automatic way to rotate-blit a surface using DirectDraw (but you can use D3D Immediate Mode).

Lock the surfaces, then do some sin/cos wrangling. You should be able to find the algo around here somewhere.

Mason McCuskey
Spin Studios
www.spin-studios.com

Founder, Cuttlefish Industries
The Cuttlefish Engine lets anyone develop great games for iPad, iPhone, Android, WP7, the web, and more!
Advertisement
DirectDraw's 'Blt' function includes support for rotating the blitted image, using the flag DDBLT_ROTATIONANGLE, and holding the angle within the DDBltFx structure, check it out in the SDK, for DX7 it is under Index title 'Blt (IDirectDrawSurface7) [C++]'

Zark, is that supported in emulation or does it only work if the gfx card does it?

Mason McCuskey
Spin Studios
www.spin-studios.com

Founder, Cuttlefish Industries
The Cuttlefish Engine lets anyone develop great games for iPad, iPhone, Android, WP7, the web, and more!
DirectDraw's bitmap rotation thing isn't supported in software, so you're out of luck if your card doesn't support it.

The way I've always done it (until I switched to OpenGL ) is with DrawPrimitive. Just make a texture out of your bitmap and texture it onto a polygon. I know Mark Feldman wrote a nice DrawPrimitive tutorial, but I can't remember where it is...check the 3D section of this site

Yeah, that's the way I've always done it too. D3DIM isn't nearly as complex as I originally thought it was... I dreaded adding support for it until I realized it is basically as easy (or even easier) than DirectDraw.

Mason McCuskey
Spin Studios
www.spin-studios.com

Founder, Cuttlefish Industries
The Cuttlefish Engine lets anyone develop great games for iPad, iPhone, Android, WP7, the web, and more!
If you don't feel like diving into 3D to solve this one, just prerotate the graphics in your graphics creation software in even increments, then load them into your software and blit the correctly rotated one for the current orientation of the picture. (You only have to do 90 degrees, then in-game you can do a quick 90, 180, or 270 degree rotate). This way will (sorry to say) get higher quality rotation than 3D texture rotations because, most likely, you are rotating higher-resolution bitmaps then downsampling them to save to file. The higher source resolution all but guarantees a higher quality rotate. Also, the graphics software you are using (for example, Photoshop) has all the time in the world to make use of high quality yet time consuming calculations to insure a high quality result.

Anyway, just my $.02 to this thread.

- Splat

I think I saw this in 3DGPL: the coordinates with the ' are the new rotated coordinates:

x' = y*sin(a) + x*cos(a)
y' = y*cos(a) + (-x*sin(a))

your formula is correct for _pure_ 2d vertex rotations but lefts out chunks when applied to a bitmap. there are better/faster methods which i don't wanna explain coz there are lots of dox about that topic
I have tried to use the RotationAngle now... but it seems like it isn´t supported, so I still can´t rotate the bitmap. Is there any other easy way to do it?? Maby there is som article or a tutorial about it somewhere? Does anyone know?

there is the PlgBlt... you could use it when loading... (you have to only create one image and its mask then). i think you have to make sure the surface is completely filled with the transparent color first, plus that the max width and height are big enough to encompass the rotated image (corners), and use the mask to prevent PlgBlt from messing up your transp color.

BOOL PlgBlt(
HDC hdcDest, // handle to destination device context
CONST POINT *lpPoint,
// vertices of destination parallelogram
HDC hdcSrc, // handle to source device context
int nXSrc, // x-coord. of upper-left corner of source rect.
int nYSrc, // y-coord. of upper-left corner of source rect.
int nWidth, // width of source rectangle
int nHeight, // height of source rectangle
HBITMAP hbmMask, // handle to bitmask
int xMask, // x-coord. of upper-left corner of bitmask rect.
int yMask // y-coord. of upper-left corner of bitmask rect.
);

This topic is closed to new replies.

Advertisement