🎉 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 a bitmap 2d with ddraw

Started by
5 comments, last by :-) 24 years, 5 months ago
If I want to rotate a bitmap 2d with ddraw, do I have to remake the pic to a pixel array first or is there any funcion for it? if not.... how do I remake the pic to a pixel array???
:-)
Advertisement
I''m assuming you''re trying to get direct access to the pixels in a surface? Use surf->Lock to get a LPDDSURFACEDESC2. The pixel memory is at the lpSurface member of the surfacedesc. You can copy it out into your own array to avoid multiple locking to read the surface memory. (You should read the docs on "Accessing Surface Memory Directly" as there are a few tricky issues like the Pitch and the format of the pixels).

I''ve found that this method of rotating bitmaps is pretty slow. If you can pre-rotate a bunch of bitmaps that''s much faster (and better looking), and using Direct3D to render bitmaps as textures has even more possibilities (but is much more complicated to set up).


-ns-
Damn that''s annoying how if I forget to type in my password it doesn''t error and instead posts from "Anonymous Poster". Arrrrggghh...


-ns-
-ns-
Thanks... but I think d3d looks pretty difficult. Do you
or anybody else) know how to rotate a bitmap with d3d in 2d?
Will this go slow if I´m running the game on a computer without a 3d card?
:-)
If you''re graphix card supports hardware rotating, you can use the Blt function to rotate surfaces. See the SDK for more info.
Thats another downside of the d3d rotation, if they don't have a 3d card it won't work (unless you use the software emulation which will probably be too slow). Also, there are some limits on the size of your bitmaps (textures) and their dimensions with D3D.
I forgot about those rotation blt functions, they might work but I havn't seen alot of cards that support it - I wrote my own 2d rotation routines when it appeared that these capabilities were not available on most of the cards I had (then again, I didn't have a ton of cards so maybe it's out there). The 2d routines I wrote used the lock/unlock method (real-time rotation) and were relatively slow. If I were going to redo it I'd use prerotated bitmaps.
The D3D method is easy, but to set up and become familiar with D3D itself and the way it works presents a pretty big learning curve especially if you've never worked with 3D before.
At any rate, to do it once you have D3D up and running (between a beginscene and and endscene):

1) Make an array of 4 D3DTLVERTEX's.
2) Set the sx,sy (screenx, screeny) values of them to the LL,UL,LR,UR corners of the destination of the bitmap.
3) Set the tu,tv values of them to (0,1) (0,0) (1,1) (1,0) respectively
4) Set the color to white for each vertex
5) set the sy to 0 and the rhw value to 1
6) Disable fog and depth buffers
7) Set the texture
8) draw primitive, giving the array of D3DTLVERTEX's as a triangle strip

Like I said, there are easier ways to do it, but this can provide some nice effects like rotation, alpha blending, fades, etc.


-ns-


Edited by - NightShade on 1/11/00 1:22:16 PM
-ns-
If you are rotating only by multiples of 90 degree angles, then it would be easy, lock the surface like that guy said to get access to the pixels. If you want to be able to rotate it on any angle between 0 to 360, then I aint even gonna help you. That would be such a pain in the ass routine to write. Especially since each rotation would have a different surface size.

This topic is closed to new replies.

Advertisement