Create antialising font
Hi,
I wanna know how can I create an antialiasing font using CreateFont function..
I'm working on OpenGL.
thanx
here's the routine i use to create antialiased strings into textures in gl.
char *fonts[] = { "Times New Roman", "Arial",};void texture_text(Texture *tex, unsigned font_index, char *string, unsigned size, int xpos, int ypos, unsigned color) { const unsigned w = tex->get_w(); const unsigned h = tex->get_h(); const unsigned width = 1 << w; const unsigned height = 1 << h; const char *font_name = fonts[font_index]; unsigned *ptr = (unsigned*)tex->get_data(); HDC hdc = GetDC(0); HBITMAP bitmap = CreateCompatibleBitmap(hdc, width << 2, height << 2); HDC hdc_mem = CreateCompatibleDC(hdc); SelectObject(hdc_mem, bitmap); static LOGFONT lf = {0, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, 0, ANTIALIASED_QUALITY, 0, 0}; lf.lfHeight = -int(size) * 4; strcpy(lf.lfFaceName, font_name); HFONT font = CreateFontIndirect(&lf); SetBkColor(hdc_mem, 0); SelectObject(hdc_mem, font); SetTextColor(hdc_mem, 0xFF0000); SetTextAlign(hdc_mem, TA_BASELINE | TA_LEFT | TA_NOUPDATECP); TextOut(hdc_mem, xpos * 4, ypos * 4, string, unsigned(strlen(string))); unsigned *buffer = new unsigned[width * height * 4 * 4]; static BITMAPINFO bi = {{sizeof(BITMAPINFOHEADER), 0, 0, 1, 32, BI_RGB, 0, 0, 0, 0, 0}, {0 ,0, 0}}; bi.bmiHeader.biWidth = width * 4; bi.bmiHeader.biHeight = int(height * 4); GetDIBits(hdc_mem, bitmap, 0, height * 4, buffer, &bi, DIB_RGB_COLORS); DeleteDC(hdc_mem); DeleteObject(bitmap); DeleteObject(font); unsigned color_alpha = color >> 24; unsigned int *src = buffer; for (unsigned y = 0; y < height; y++) { for (unsigned x = 0; x < width; x++) { unsigned accum = 0; unsigned offs = (x << 2) + (y << 4) * width; for (unsigned i=4; i; i--) { accum += src[offs] + src[offs+1] + src[offs+2] + src[offs+3]; offs += width << 2; } unsigned char alpha = unsigned char(accum >> 4); alpha = ( alpha * color_alpha ) >> 8; unsigned int rb1 = *ptr & 0xFF00FF; unsigned int g1 = *ptr & 0x00FF00; unsigned int rb2 = color & 0xFF00FF; unsigned int g2 = color & 0x00FF00; unsigned dst_alpha = *ptr >> 24; dst_alpha += alpha; if (dst_alpha > 255) dst_alpha = 255; *ptr++ = ((rb1+(((rb2-rb1)*alpha)>>8))&0xFF00FF|(g1+(((g2-g1)*alpha)>>8))&0x00FF00) | (dst_alpha << 24); } } delete[] buffer;}
man glutStrokeCharacter
witch glLineWidth(2) and GL_LINE_SMOOTH. i have great results with this.
witch glLineWidth(2) and GL_LINE_SMOOTH. i have great results with this.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement