Archived

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

Alpha sprite blitting

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Yup! It doesn't work, never has, and I doubt if it ever will (MS have been promising alpha support forever, but it's still not there.... Maybe with DX9231, who knows).

So, it's time to get your hands dirty and code it yourself !

/Niels

Share this post


Link to post
Share on other sites
DirectDraw doesn't support it in Hardware.

It "was" going to be in DX7, but turns out they decided against it.
Like I said, I have the ZIP file of a cool example that shows Sprites as D3D Quads rendered with alpha blending.

If you want it, just email me at:
rbenson@earthlink.net

Keeb

Share this post


Link to post
Share on other sites
No that's OK.
I have another question - I cant get the dwRotationAngle to work either - in fact it doesnt even blit at all!! I use DDBLT_ROTATIONANGLE or whatever it is, but - no luck.
Anybody got some code?

Share this post


Link to post
Share on other sites
DirectX is really a great name... "DirectAccess" - That is exactly all you get: Direct access to the framebuffer and HW features. The Docs spend quite a few pages talking HAL and HEL, just a shame that HEL never showed up ... Which leaves me wondering if you really needed a COM interface to get a pointer to a piece of memory.. Oh well ...

/Niels

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
hmmm... i think it is the old alpha problem again...

Ok, guys. Look at http://cust.nol.at/ppee/ for a quick end to this problem. The code is for 16 bit, but if you look closer it will be easy to transport it for 24 or 32.

Bye.

Share this post


Link to post
Share on other sites
Here I am a nice guy!

// Container structure for RGB masks
typedef struct _RGBMASK
{
ULONG rgbRed;
ULONG rgbGreen;
ULONG rgbBlue;
} RGBMASK;

// Container structure for (5,6,5 or 5,5,5 and masking)
typedef struct _RGB16
{
RGBQUAD depth;
RGBQUAD amount;
RGBQUAD position;
RGBMASK mask;
} RGB16;

extern RGB16 rgb16;

extern int RedMask, GreenMask, BlueMask; // RGB Masks
extern int RedPos, GreenPos, BluePos; // RGB Positions

#define RED(p) (p >> RedPos) // Extracts Red color
#define GREEN(p) ((p & GreenMask) >> GreenPos) // Extracts Green color
#define BLUE(p) (p & BlueMask) // Extracts Blue color
#define RGB16(r, g, b) ((r << RedPos) | (g << GreenPos) | b) // Creates RGB pixel even if card is in 555 or 565

void DDGetPixelFormat()
{
DDSURFACEDESC2 ddsd; // DirectDraw Surface Description
BYTE shiftcount; // Shift Counter

// Get a surface despriction.
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_PIXELFORMAT;
FrontSurf->Surface->GetSurfaceDesc(&ddsd);
// Fill in the masking values for extracting colors.
rgb16.mask.rgbRed = ddsd.ddpfPixelFormat.dwRBitMask;
rgb16.mask.rgbGreen = ddsd.ddpfPixelFormat.dwGBitMask;
rgb16.mask.rgbBlue = ddsd.ddpfPixelFormat.dwBBitMask;

// Get red surface information.
shiftcount = 0;
while(!(ddsd.ddpfPixelFormat.dwRBitMask & 1))
{
ddsd.ddpfPixelFormat.dwRBitMask >>= 1;
shiftcount++;
}
rgb16.depth.rgbRed = (BYTE)ddsd.ddpfPixelFormat.dwRBitMask;
rgb16.position.rgbRed = shiftcount;
rgb16.amount.rgbRed = (ddsd.ddpfPixelFormat.dwRBitMask == 0x1f) ? 3 : 2;

// Get green surface information.
shiftcount = 0;
while(!(ddsd.ddpfPixelFormat.dwGBitMask & 1))
{
ddsd.ddpfPixelFormat.dwGBitMask >>= 1;
shiftcount++;
}
rgb16.depth.rgbGreen =(BYTE)ddsd.ddpfPixelFormat.dwGBitMask;
rgb16.position.rgbGreen = shiftcount;
rgb16.amount.rgbGreen = (ddsd.ddpfPixelFormat.dwGBitMask == 0x1f) ? 3 : 2;

// Get Blue surface information.
shiftcount = 0;
while(!(ddsd.ddpfPixelFormat.dwBBitMask & 1))
{
ddsd.ddpfPixelFormat.dwBBitMask >>= 1;
shiftcount++;
}
rgb16.depth.rgbBlue =(BYTE)ddsd.ddpfPixelFormat.dwBBitMask;
rgb16.position.rgbBlue = shiftcount;
rgb16.amount.rgbBlue = (ddsd.ddpfPixelFormat.dwBBitMask == 0x1f) ? 3 : 2;
// Fill in variables so we dont' have to access the structure anymore.
RedMask = rgb16.mask.rgbRed; // Red Mask
GreenMask = rgb16.mask.rgbGreen; // Green Mask
BlueMask = rgb16.mask.rgbBlue; // Blue Mask
RedPos = rgb16.position.rgbRed; // Red Position
GreenPos = rgb16.position.rgbGreen; // Green Position
BluePos = rgb16.position.rgbBlue; // Blue Position
}

//This will blit the src color you pass to it with the background color at x,y location, you can have 256 levels of alpha. The math is already optimized but doing pixel by pixel is overkill you must find a way to optimize even more
int DDPlotAlphaPixel(int pX, int pY, int pR, int pG, int pB, int pA, G16SURFACEPTR pSurf)
{
int Alpha = pA;

USHORT src = RGB16(pR,pG,pB);
USHORT dest = ((USHORT*)pSurf->Buffer)[pX + (pY*pSurf->Pitch>>1)];

dest = ((RedMask & ((dest & RedMask) + ((int)(((int)(src & RedMask) - (int)(dest & RedMask)) * Alpha) >>8))) |
(GreenMask & ((dest & GreenMask) + ((int)(((int)(src & GreenMask) - (int)(dest & GreenMask)) * Alpha) >>8))) |
(BlueMask & ((dest & BlueMask) + ((int)(((int)(src & BlueMask) - (int)(dest & BlueMask)) * Alpha) >>8))));

((USHORT*)pSurf->Buffer)[pX + (pY*pSurf->Pitch>>1)] = dest;

return(1);
}

// Does additive blending meanning. Good for doing explosions and stuff. What you do is you draw the explosions in you bitmao on a black background. After when you blit you add the background color that you got at x,y location on you screen to the bitmap. So black wich is 0 plus the color at x,y location gives the same color but. lets say the back ground color plus yellow somewhere in you fire will give the mixed color. This wau you wont have a black ora around your sprite explosion when you blit on a non black background.
int DDAddToPixel(int pX, int pY, int pR, int pG, int pB, G16SURFACEPTR pSurf)
{
USHORT tdest = 0;
USHORT t;

USHORT src = ((USHORT*)pSurf->Buffer)[pX + (pY*pSurf->Pitch>>1)];
USHORT dest = RGB16(pR,pG,pB);

t = (src & RedMask) + (dest & RedMask);
if(t > RedMask) t = RedMask;
tdest |= t;

t = (src & GreenMask) + (dest & GreenMask);
if(t > GreenMask) t = GreenMask;
tdest |= t;

t = (src & BlueMask) + (dest & BlueMask);
if(t > BlueMask) t = BlueMask;
tdest |= t;

((USHORT*)pSurf->Buffer)[pX + (pY*pSurf->Pitch>>1)] = tdest;

return(1);
}

Share this post


Link to post
Share on other sites
Hi, I can't seem to get the "alpha" feature of IDirectDrawSurface3->Blt to work...it just blits it opaque or not at all.
Anybody else experianced this / got some example code?

thanks

Share this post


Link to post
Share on other sites