Skip to main content
gamedev.net
🔒 Locked

alpha maps

Started by wannabean333 0 replies 500+ views
Original Post
wannabean333
wannabean333
hey everyone- I'm still upgrading my 2d directdraw engine, and one of the next steps is to add alpha maps for lighting effects. I am using bitmaps, but I want to try to have bitmaps that show alpha values from 0-255. Here's my questions: To implement alpha maps, should I use bitmap files or should I use text files? What would I insert/change to get my code (shown below) to support usage of alpha maps?
// Initialize the pointers to the first pixel in the rectangle
		lpSprite += (srcRect.top * SpritePitch) + (srcRect.left * 2);
		lpDest   += (lDestY * dPitch) + (lDestX * 2);

		// Set the horizontal padding
		sbuf = (WORD)(SpritePitch - (2 * width));
		dbuf = (WORD)(dPitch - (2 * width));

		// Is the Sprite width odd or even?
		if (width % 2 == 1)
		{
			oddWidth = TRUE;
			width = (width - 1) / 2; //div by 2, processing 2 pixels at a time.
		}
		else
			width = width / 2;  //div by 2, processing 2 pixels at a time.


		i = height;
		do
		{
			if (oddWidth)
			{
				sTemp = *((WORD*)lpSprite);

				if (sTemp != ColorKey)
				{
					dTemp = *((WORD*)lpDest);
					sb = sTemp & 0x1f;
					db = dTemp & 0x1f;
					sg = (sTemp >> 5) & 0x3f;
					dg = (dTemp >> 5) & 0x3f;
					sr = (sTemp >> 11) & 0x1f;
					dr = (dTemp >> 11) & 0x1f;

					*((WORD*)lpDest) = (WORD)((ALPHA * (sb - db) >> 8) + db |
						((ALPHA * (sg - dg) >> 8) + dg) << 5 |
						((ALPHA * (sr - dr) >> 8) + dr) << 11);
				}

				lpDest   += 2;
				lpSprite += 2;
			}
			j = width;
			do
			{
				sTemp = *((DWORD*)lpSprite);

				if ( sTemp != doubleColorKey )
				{
					dTemp = *((DWORD*)lpDest);

					sb = sTemp & 0x001F001F;
					db = dTemp & 0x001F001F;
					sg = (sTemp >> 5)  & 0x003F003F;
					dg = (dTemp >> 5)  & 0x003F003F;
					sr = (sTemp >> 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;

					if ( (sTemp >> 16) == ColorKey )
							Result = (Result & 0xFFFF) | (dTemp & 0xFFFF0000);
					else if ( (sTemp & 0xFFFF) == ColorKey )
							Result = (Result & 0xFFFF0000) | (dTemp & 0xFFFF);

					*((DWORD*)lpDest) = Result;
				}
				lpDest    += 4;
				lpSprite  += 4;

			}while (--j > 0);

			lpDest   += dbuf;
			lpSprite += sbuf;

		}while (--i > 0);

Topic Locked

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

Sign in to reply to this topic.