jamesleighe
July 12th, 2010, 11:53 AM
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:
// 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?
Here is some 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?