Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectDraw - Alpha Blending and Rotation

Started by deadimp Feb 27, 2005 at 6:49 PM 2 replies 6.6k views
Original Post
deadimp
deadimp
I've recently torn out some of the Win32 blitting functions I had used in my graphics engine and replaced them with the DirectDraw versions, and I was wondering about DirectDraw's capabilities of image rotation and alpha blending. These two things were the main reason I did this (plus the fact that BitBlt was too slow with big images), and I was rather excited about the prospect of being able to use alpha blending AND rotation using DirectDraw, instead of D3D. Yet, of course, I was disappointed... When I attempted to use angle rotation in "IDirectDraw::Blt()", it returned an error that there was no hardware support. Also, I tried using alpha blending in the same function, and again I was disappointed, again. Is there some way to make this work? Am I doing something wrong in my functions? Here's the code I am using:
//Variables being used:
LPDIRECTDRAWSURFACE lpDDS; //The currently focused on DD surface
HDC hdc; //The corresponding HDC with the surface
CSprite &sprite //Reference, not pointer
LPDIRECTDRAWSURFACE CSprite::ddsSprite;
bool CSprite::transparent;
UINT CSprite::tColor; //Transparent color
long srcX, srcY, srcW, srcH, dx, dy; //Source and destination variables
BYTE alpha; //Alpha value
//Code:
 DDBLTFX fxCur;
 DWORD fxFlags;
 ZeroMemory(&fxCur,sizeof(fxCur));
 fxCur.dwSize=sizeof(fxCur);
 fxFlags=DDBLT_WAIT;
 RECT rectSrc={srcX,srcY,srcX+srcW,srcY+srcH}, rectDest={dx,dy,dx+srcW,dy+srcH};
 if (sprite.transparent) {
  //Another question: How do you make tranpsarency using a certain color?
  DDCOLORKEY fxColorKey={0xFF,0xFF}; //This sort-of works
  fxCur.ddckSrcColorkey=fxColorKey;
  fxFlags|=DDBLT_KEYSRCOVERRIDE;
 }
 if (alpha!=255) {
  fxCur.dwAlphaSrcConst=alpha;
  fxFlags|=DDBLT_ALPHASRCCONSTOVERRIDE;
 }
 //The rotation is a random test
 fxCur.dwRotationAngle=4500;
 fxFlags|=DDBLT_ROTATIONANGLE;

 lpDDS->ReleaseDC(hdc);
 HRESULT hresult=lpDDS->Blt(&rectDest,sprite.ddsSprite,&rectSrc,fxFlags,&fxCur);
 lpDDS->GetDC(&hdc);



Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
Daerax
Daerax
There is nothing wrong with the code, the thing is, almost no hardware supports those calling parameters (and I do not think there is any software fallback code either). A possible peak in 2D hardware simply was not reached because it came at the wrong time. There was a clash and it so happened that video cards tunred to focus towards 3D hardware acceleration and not 2D as that market proved to be more ludicrous and possesed of more potential. Directdraw8 was supposed to have surfaces that could be blended and rotated and lots of cool stuff. No one ever pushed it. You can still see the place holders in directdraw7..

Are you trying to (a) make a game [and focus on game programming] or do (b) graphics programming?

if a then I suggest you take up Direct3d. It is easy and there is much information on how to do 2d in 3d. You can easily do lighting, heightmapping, shadows, scaling, rotating and blending all hardware accelerated in it (and still not touch any 3d details). If b then I suggest you read up on software methods in alpha blending and software rotation. To start:

x' = xcos(θ) - ysin(θ) + cx
y' = xsin(θ) + ycos(θ;) + cy

Where θ is the angle of rotation and c is the pixel location of the centre of your sprite.

These methods are gonna be compuationally expensive and slow
-------------
Cipher3D
Cipher3D
I shall rant and rave about the obligatory "textured quads."

There are many freely downloadable libraries that make use of 3d textured quads, which can be treated as RECTs but they have added perks such as translucency and rotation.

Or, what I suggest is writing your own textured quad implementation. It's easy, and there's several articles (some being better than the others) on GameDev.net that detail the implementation of textured quads in the higher DirectX's (>= 8).

For 9 it's just a matter of replacing the 8 in data types and function calls with a 9 [grin].

Good luck, and PM me if you need some more information!
I eat heart attacks
Daerax
Daerax
I just remembered I actually posted an untried method on combined skewing and rotating in this thread. In which I also go over rotations slightly more thoroughly.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.