Jump to content
  • Advertisement


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


Alpha-PutPixel woes

This topic is 6918 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

i've been trying (so far in vain) to create a function to 'transparently' put individual pixels to a directdraw surface using alpha blending, the below code produces black pixels (or close to black...) ...the code was adapted from the gamedev article "MMX enhanced Alpha Blending" (although this func does not use mmx...) anyone see any problems with it?
//NOTE, the destination surface must be locked prior to calling this functoin
void PutPixel_Trans(CDXSurface* pDestSurf, LONG lDestX, LONG lDestY, DWORD COLOR, WORD ALPHA)
	BYTE* lpDest;
	WORD dPitch;
	DWORD dTemp;
	DWORD sr,sg,sb,dr,dg,db;
	DWORD Result;
	BOOL oddWidth = FALSE;

	// Check the ALPHA value
	if (ALPHA < 0)
		ALPHA	= 0;
	else if (ALPHA > 256)
		ALPHA	= 256;

	//get color depth
	int BPP		= pDestSurf->m_DDSD.ddpfPixelFormat.dwRGBBitCount;

    // Set the pitch for both surfaces
    dPitch		= (WORD)pDestSurf->m_DDSD.lPitch;

    // Initialize the pointers to the upper left hand corner of surface
    lpDest		= (BYTE*)pDestSurf->m_DDSD.lpSurface;

	// Do some work outside of the loop
	PLUS64		= 64 / (64 << 16);
	ALPHABY4	= (ALPHA / 4) / ((ALPHA / 4) << 16);

	case 16:
			lpDest	+= (lDestY * dPitch) + (lDestX * 2);
			dTemp = *((DWORD*)lpDest);
			//quit at the first sign of an error!

		sb = COLOR & 0x001F001F;
		db = dTemp & 0x001F001F;
		sg = (COLOR >> 5)  & 0x003F003F;
		dg = (dTemp >> 5)  & 0x003F003F;
		sr = (COLOR >> 11) & 0x001F001F;
		dr = (dTemp >> 11) & 0x001F001F;

		BLUEC  = ((((ALPHA * ((sb + PLUS64) - db)) >> 8) + db) - ALPHABY4) & 0x001F001F;
		GREENC = (((((ALPHA * ((sg + PLUS64) - dg)) >> 8) + dg) - ALPHABY4) & 0x003F003F) << 5;
		REDC   = (((((ALPHA * ((sr + PLUS64) - dr)) >> 8) + dr) - ALPHABY4) & 0x001F001F) << 11;

		Result = BLUEC / GREENC / REDC;
		Result = (Result & 0xFFFF0000) / (dTemp & 0xFFFF);

		*((DWORD*)lpDest) = Result;
	//TODO: more BPP's!

Edited by - POINT on 5/9/00 12:13:46 PM

Share this post

Link to post
Share on other sites
For great examples on how to use Alpha Blending, check out the NukeDX libraries from http://www.nukesoftware.dk

NukeDX is a good wrapper for DirectDraw that handles dirty rectangles, (drawing only parts that are needed on the screen, instead of the whole screen every time), loading various types of bitmaps, 555 versus 556 in 16 bit color is done automatically, and yes, alphablending and rotation. The alphablending is nice! You can simply specify a seperate bitmap as the alpha channel and it takes intensity values from that image, (usually a grayscale image).

If you don''t use the libraries, at the very least you could take a look at the source, (which is also MMX accelerated)


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!