Jump to content
  • Advertisement
Sign in to follow this  

32-bit Alpha Bitmaps and GDI.... (Fun alert)

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

So anyway, here I am working on my layered window demo, creating my 32 bit bitmaps with an alpha channel etc. I select the bitmap into a valid device context, and pass it to UpdateLayeredWindow. It works. So I decide to draw text on my DC that I pass to UpdateLayeredWindow. As simple as calling DrawText or TextOut after I've set the colours and background mode, right? WRONG. What happens is that DrawText and TextOut both ignore my alpha channel, and just dump 0 to it. So I end up with a semitransparent window with "STORM System V.1" cut out. My paint procedure:
		case WM_PAINT:
			SystemParametersInfo(SPI_GETWORKAREA, 0, &rWorkspace, 0);
			pXY.x	=	rWorkspace.right - sBitmapXY.cx;
			pXY.y	=	rWorkspace.bottom - sBitmapXY.cy;

			hBitmap	=	CreateCompatibleDC(NULL);
			hScreen	=	CreateCompatibleDC(NULL);
			SelectObject(hBitmap, g_hTabbitBmp);
			SelectObject(hBitmap, g_hTabbitFntLg);
			SetBkMode(hBitmap, TRANSPARENT);
			SetTextColor(hBitmap, RGB(127, 127, 127));

			TextOut(hBitmap, 0, 0, SC_STORMSYSTEM, _tcslen(SC_STORMSYSTEM));
			UpdateLayeredWindow(g_hTabbitWnd, hScreen, &pXY, &sBitmapXY, hBitmap, &pDeviceContextStart, RGB(07, 12, 89), &fBlend, ULW_ALPHA);
			return 0;
and the setup for my blend function...
			fBlend.BlendOp				=	AC_SRC_OVER;
			fBlend.BlendFlags			=	0;
			fBlend.SourceConstantAlpha	=	255;
			fBlend.AlphaFormat			=	AC_SRC_ALPHA;
I've sort of locked on to the fact that SetTextColor(HDC, COLORREF) uses COLORREF, which is a 32 bit value. So I tried setting my alpha channel to 255 with that but no, it didn't work. Setting up an RGBQUAD didn't work either. Any help on how to draw the damn text with 255 alpha and Red: 125, Green: 167, Blue: 216 would be VERY appreciated. And if I'm doing something stupid, kick me.

Share this post

Link to post
Share on other sites
Alpha support in GDI is sketch at best...

If all else fails you could render your text to an offscreen dib section, if necessary walk the pixels and fixup the alpha, then call AlphaBlend to blt it to a window.

Share this post

Link to post
Share on other sites
I had considered myself fairly familiar with GDI and the Win32 API (as well as with finding things in the MSDN Library, hehe); but I don't know and can't find the solution to this problem after some serious searching. Leaving out alpha channel support from the text-drawing functions seems like a major oversight, so it wouldn't hurt to check things out with as simple of a test-case as you can compile and see if it works then; but if not, then you might need to use some sort of mask or other function that fixes or inverts the alpha in the text. I don't know of any off the top of my head...sorry I couldn't be of more help.

Share this post

Link to post
Share on other sites
Looks like I'm going to have to do that. Mike Sutton gave me this useful reply in the M$ community boards:

Most GDI functions have no idea what alpha is and as such simply use a
24-bit colour, ignoring the high byte. What I do is to render the text as
an alpha mask to an 8-bit greyscale buffer then use that as the alpha
channel in a 32-bit DIB and inject colour into the RGB channels, then
AlphaBlend() that to the window.
Hope this helps,


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!