CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2009
    Posts
    23

    Drawing AA Text to a DIBitmap

    So, the idea is I'm trying to draw anti-aliased text to a DIB so that I can bitcopy that onto a texture for use as a bitmap-font.

    Here is some code:
    Code:
    	// create a GDI font
    	HFONT fontHandle = CreateFontA (
    		size,					// height
    		0,					// width
    		0,					// escapement
    		0,					// orientation
    		FW_NORMAL,				// weight
    		FALSE,					// italic
    		FALSE,					// underline
    		FALSE,					// strikeout
    		ANSI_CHARSET,				// char set
    		OUT_OUTLINE_PRECIS,			// out precision
    		CLIP_DEFAULT_PRECIS,			// clip precision
    		ANTIALIASED_QUALITY,			// quality
    		VARIABLE_PITCH || FF_DONTCARE,		// pitch and family
    		data_->face.CString ());		// face name
    
    	HDC deviceContext = CreateCompatibleDC (NULL);
    	if (!deviceContext)
    		assert (0);
    
    	// create a bitmap to render individual glyphs to
    	BITMAPINFO bitmapInfo;
    	memset (&bitmapInfo, 0, sizeof (bitmapInfo));
    	bitmapInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
    	bitmapInfo.bmiHeader.biWidth = glyphSize;
    	// negative height to store bitmatp data in raster scan order
    	bitmapInfo.bmiHeader.biHeight = -glyphSize;
    	bitmapInfo.bmiHeader.biPlanes = 1;
    	bitmapInfo.bmiHeader.biBitCount = 32;
    
    	void* bitmapMemoryBase;
    	HBITMAP bitmap = CreateDIBSection (NULL, &bitmapInfo, DIB_RGB_COLORS, &bitmapMemoryBase, NULL, NULL);
    	if (!bitmap)
    		assert (0);
    
    	// select in objects & setup for rendering
    	SelectObject (deviceContext, fontHandle);
    	SelectObject (deviceContext, bitmap);
    	SetTextColor (deviceContext, RGB (255, 255, 255));
    	SetBkColor (deviceContext, RGB (0, 0, 0));
    	SetBkMode (deviceContext, OPAQUE);
    
    
    (some time later)
    	if (DrawTextA (deviceContext, (LPCSTR)stringBuf.CString (), 1, &rect, DT_LEFT | DT_SINGLELINE | DT_NOCLIP) == 0)
    			assert (0);
    Using this method the text comes out without anti-aliasing.

    I found that I can get AA to work if I use the "SCREEN" dc and a DDB instead of a DIB but that renders visibly to the screen...

    Any ideas?

  2. #2
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Drawing AA Text to a DIBitmap

    My guess would be that you somehow lose the alpha-channel information for your DIB section. In most cases GDI functions can only process the RGB data, when anti-aliasing deals with RGBA or ARGB (meaning that there's also a byte for an alpha channel). Since your code sample above doesn't show how you deal with bitmapMemoryBase my guess would be that...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured