Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Alpha sprite blitting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 kieren_j   Members   -  Reputation: 100

Like
Likes
Like

Posted 29 October 1999 - 11:23 PM

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


Sponsor:

#2 Niels   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 October 1999 - 11:13 AM

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


#3 Keebler   Members   -  Reputation: 126

Like
Likes
Like

Posted 27 October 1999 - 11:26 AM

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


#4 kieren_j   Members   -  Reputation: 100

Like
Likes
Like

Posted 28 October 1999 - 07:32 AM

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?

#5 BlueNexus   Members   -  Reputation: 122

Like
Likes
Like

Posted 28 October 1999 - 08:22 AM

Another great DirectDraw feature. There's no software emulation for rotating, so if its not supported by your hardware, you're out of luck.

BlueNexus


#6 Keebler   Members   -  Reputation: 126

Like
Likes
Like

Posted 28 October 1999 - 08:26 AM

I wanted to use that operation as well but like BlueNexus said it's only in Hardware and many of the good cards don't even support it. Better get cozy with Sin() and Cos()

Keeb


#7 Niels   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 October 1999 - 04:01 AM

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


#8 mmcconnell   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 October 1999 - 07:29 AM

Can anyone point me to some good reference material for writing my own blitter with alpha channel?

Thanks,
Marcus


#9 kieren_j   Members   -  Reputation: 100

Like
Likes
Like

Posted 29 October 1999 - 08:43 AM

Search on gamedev, there was an article - using MMX or something.
The thing is my card -DOES- support rotation, but has anybody got some demo code?

#10 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 29 October 1999 - 09:30 AM

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.


#11 voodoo   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 October 1999 - 11:21 PM

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);
}


#12 voodoo   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 October 1999 - 11:23 PM

Now if olny I can get unlazy and begin working on my engine again




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS