So, it's time to get your hands dirty and code it yourself !
/Niels
So, it's time to get your hands dirty and code it yourself !
/Niels
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
BlueNexus
Keeb
/Niels
Thanks,
Marcus
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.
// 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);
}