////////////////////////////////////////////////////////////////////// // Create the font to display the text ////////////////////////////////////////////////////////////////////// BOOL CGLFont::CreateFont(CDC* pDrawDC, char* fontname) { m_uiListID = glGenLists(FONTLIST); if(pDrawDC == NULL || m_uiListID == 0) { return FALSE; } //Create the font to display CFont newfont; CFont* oldfont; BOOL bresult; GLYPHMETRICSFLOAT gmf[FONTLIST]; if(fontname != NULL) { bresult = newfont.CreateFont(-12, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE|DEFAULT_PITCH, fontname); //if new font failed to be created if(!bresult) { return FALSE; } oldfont = pDrawDC->SelectObject(&newfont); } else { oldfont = (CFont*)pDrawDC->SelectStockObject(SYSTEM_FONT); } if(m_FontType == GL_FONT_SOLID) { bresult = wglUseFontOutlines(pDrawDC->m_hDC, 0, FONTLIST, m_uiListID, 0.0f, (float)m_dThick, WGL_FONT_POLYGONS, gmf); } else if(m_FontType == GL_FONT_LINE) { bresult = wglUseFontOutlines(pDrawDC->m_hDC, 0, FONTLIST, m_uiListID, 0.0f, (float)m_dThick, WGL_FONT_LINES, gmf); } pDrawDC->SelectObject(oldfont); newfont.DeleteObject(); if(!bresult) { return FALSE; } return TRUE; }
int GameClass::LoadStandard3DFont(char* name,float extrude,int flags,int italic) { HFONT hFont; Std3DFontBase=glGenLists(MAX_CHARS); size_t length=strlen(name); wchar_t* newStr = new wchar_t[length+1]; mbtowc(newStr,name,length+1); hFont=CreateFont( 0,0,0,0, flags, italic, FALSE,FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, newStr); delete [] newStr; if(!hFont) return 0; hOldFont=(HFONT)SelectObject(GLWindow.Settings.hDC,hFont); wglUseFontOutlines( GLWindow.Settings.hDC, 0,MAX_CHARS-1, Std3DFontBase, 0, extrude, WGL_FONT_POLYGONS, GlyphInfo); return 1; }
void CGLLogoView::CreateGLFont() { HFONT font; HFONT oldfont; font_base = glGenLists(96); font = CreateFont( -12, // Height Of Font 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_TT_ALWAYS, // Clipping Precision CLEARTYPE_NATURAL_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch L"Arial"); // Font Name oldfont = (HFONT)SelectObject(hDC, font); // Selects The Font We Want wglUseFontOutlines(hDC, 32, 96, font_base, 0.02f, 0.0001f, WGL_FONT_POLYGONS, gmf); SelectObject(hDC, oldfont); // Selects The Font We Want DeleteObject(font); // Delete The Font }
void CGLFont::Printfc3d(CString strText,HFONT hFont,float z) { HDC hdc = wglGetCurrentDC(); //设备场景 HFONT hOldFont=(HFONT)::SelectObject(hdc,hFont);//将字体选入场景 UCHAR * pChar=(UCHAR*)strText.GetBuffer(strText.GetLength());//定义字符串长度 int nListNum; //显示列表 DWORD dwChar; //字符指针 GLYPHMETRICSFLOAT pgmf[1]; //轮廓字体字符集的信息 glPushMatrix(); //压入堆栈 for(int i = 0; i < strText.GetLength(); i++) { if(IsDBCSLeadByte((BYTE)pChar[i])) //是否双字节(汉字) { dwChar=(DWORD)((pChar[i]<<8)|pChar[i+1]); //取当前字符,双字节转换 i++; } else dwChar = pChar[i]; //取当前字符 nListNum = glGenLists(1); //创建列表 wglUseFontOutlines( hdc, //拥有字体的HDC dwChar, //转化为显示列表的第一个字符 1, //转化为显示列表的字符数 nListNum, //显示列表的开始 0.0f, z, //Z轴负方向的厚度 WGL_FONT_POLYGONS, //绘制字体方式 pgmf //指向存放信息的数组,为count个 ); glCallList(nListNum); //绘制显示列表 glDeleteLists(nListNum, 1); //删除列表 } glPopMatrix(); //弹出堆栈 strText.ReleaseBuffer(); //清除字符串 ::SelectObject(hdc,hOldFont); //恢复字体 }
// Build Our Bitmap Font GLvoid BuildFont(GLvoid) { // Address Buffer For Font Storage GLYPHMETRICSFLOAT gmf[256]; // Windows Font Handle HFONT font; size_t i; TCHAR c; GLfloat cellOriginX = 0.0f; GLfloat stringOriginX; GLfloat stringExtentX = 0.0f; GLfloat stringExtentY = 0.0f; // Storage For 256 Characters base = glGenLists(256); font = CreateFont(-12, 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout DEFAULT_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch _T("Tahoma")); // Font Name // Selects The Font We Created SelectObject(hDC, font); wglUseFontOutlines(hDC, // Select The Current DC 0, // Starting Character 255, // Number Of Display Lists To Build base, // Starting Display Lists 0.0f, // Deviation From The True Outlines 0.2f, // Font Thickness In The Z Direction WGL_FONT_POLYGONS, // Use Polygons, Not Lines gmf); // Address Of Buffer To Receive Data // Calculate the string extent for (i = 0; i < _tcslen(m_Text); i++) { c = m_Text[i]; stringOriginX = cellOriginX + gmf[c].gmfptGlyphOrigin.x; stringExtentX = stringOriginX + gmf[c].gmfBlackBoxX; if (gmf[c].gmfBlackBoxY > stringExtentY) stringExtentY = gmf[c].gmfBlackBoxY; cellOriginX = cellOriginX + gmf[c].gmfCellIncX; } extentX = stringExtentX; extentY = stringExtentY; }
vector<int> CglResouce::Build3DText(unsigned char *str) { vector<int> result; result.clear(); HDC hDC=wglGetCurrentDC(); //设置当前字体 SelectObject(wglGetCurrentDC(),hFont); DWORD dwChar; GLYPHMETRICSFLOAT pgmf[1]; for(size_t i=0;i<strlen((char *)str);i++) { if(IsDBCSLeadByte(str[i])) { dwChar=(DWORD)((str[i]<<8)|str[i+1]); i++; } else dwChar=str[i]; result.push_back( glGenLists(1) ); wglUseFontOutlines(hDC,dwChar,1,result.back(),0.0,0.1f,WGL_FONT_POLYGONS,pgmf); } return result; }
//http://msdn2.microsoft.com/en-us/library/ms970775.aspx void Win32Helper::setFont(const char * fontName) { fontBase = glGenLists(127); HFONT font = CreateFont( -12, 0, 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch L"Courier New" ); HDC hDC = wglGetCurrentDC(); SelectObject(hDC,font); int x = wglUseFontOutlines( hDC, __toascii(' '), // Starting Character __toascii(' ') + 126,// Number Of Display Lists To Build fontBase, // Starting Display Lists 0.0f, // Deviation From The True Outlines 0.2f, // Font Thickness In The Z Direction WGL_FONT_POLYGONS, // Use Polygons, Not Lines NULL ); DeleteObject(font); }
// Create font void COpenGlDisplay::createFont(void) { HFONT hFont; GLYPHMETRICSFLOAT agmf[128]; LOGFONT logfont; logfont.lfHeight = -10; logfont.lfWidth = 0; logfont.lfEscapement = 0; logfont.lfOrientation = 0; logfont.lfWeight = FW_BOLD; logfont.lfItalic = FALSE; logfont.lfUnderline = FALSE; logfont.lfStrikeOut = FALSE; logfont.lfCharSet = ANSI_CHARSET; logfont.lfOutPrecision = OUT_DEFAULT_PRECIS; logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; logfont.lfQuality = DEFAULT_QUALITY; logfont.lfPitchAndFamily = DEFAULT_PITCH; strcpy_s(logfont.lfFaceName, _T("Arial")); //创建字体和显示列表 hFont = CreateFontIndirect(&logfont); SelectObject(hrenderDC, hFont); nFontList = glGenLists(128); wglUseFontOutlines(hrenderDC, 0, 128, nFontList, 0.0f, 0.1f, WGL_FONT_POLYGONS, agmf); DeleteObject(hFont); }
GLvoid BuildFont(GLvoid) // Build Our Bitmap Font { HFONT font; // Windows Font ID base = glGenLists(256); // Storage For 256 Characters font = CreateFont( -12, // Height Of Font 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch "Comic Sans MS"); // Font Name SelectObject(hDC, font); // Selects The Font We Created wglUseFontOutlines( hDC, // Select The Current DC 0, // Starting Character 255, // Number Of Display Lists To Build base, // Starting Display Lists 0.0f, // Deviation From The True Outlines 0.2f, // Font Thickness In The Z Direction WGL_FONT_POLYGONS, // Use Polygons, Not Lines gmf); // Address Of Buffer To Recieve Data }
// Init3d method --------------------------------------------------------------+ bool CGLFont::Init3d(HDC hdcContext, HFONT hFont, float fDeviation, float fExtrusion, int iFormat) { if (m_FontMode != fmNone) return false; HFONT hFontOld; GLYPHMETRICSFLOAT gmf[256]; BOOL bRet; m_FontMode = fm3d; m_iList = glGenLists(256); // select font and create 3d characters: hFontOld = (HFONT)SelectObject(hdcContext, hFont); bRet = wglUseFontOutlines(hdcContext, 0, 255, m_iList, fDeviation, fExtrusion, iFormat, gmf); SelectObject(hdcContext, hFontOld); DeleteObject(hFont); // ok? if (bRet == FALSE) { glDeleteLists(m_iList, 256); return false; } // copy sizes of the characters: for (int i = 0; i < 256; ++i) { m_fSize[i][0] = gmf[i].gmfCellIncX; m_fSize[i][1] = gmf[i].gmfCellIncY; } return true; }
/** * Initialize the text for rendering on the GUI */ GLvoid textInit(GLvoid) { HDC hdc = wglGetCurrentDC(); HFONT font; /* Create our font */ font = CreateFont(-12, 0, 0, 0, FW_ULTRALIGHT, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, "Lucida Console"); SelectObject(hdc, font); base = glGenLists(256); baseOut = glGenLists(256); /* Create the font and font outline (for antialias) */ wglUseFontOutlines(hdc, 0, 255, base, 0.0, 0.0, WGL_FONT_POLYGONS, gmf); wglUseFontOutlines(hdc, 0, 255, baseOut, 0.0, 0.0, WGL_FONT_LINES, gmfOut); DeleteObject(font); }
//Define our load() function- loads up the font and gets it ready for use bool DIZ_FONT::load() { //Declare font handles for the font we want to use and whatever's currently in use HFONT font, oldFont; //Generate display lists for our font starting with our base value base = glGenLists(255); //Create a new font using our specified font info font = CreateFont( info.height, info.width, info.escAng, info.orientation, info.weight, info.italic, info.underline, info.strikeout, info.charSet, info.outPrecis, info.clipPrecis, info.outQuality, info.family, info.font); //Select our new font to use in our Device Context oldFont = (HFONT)SelectObject(*hDC, font); //Check what type of font we want if (info.type == DIZ_FONT_BITMAP) { //If we want a Bitmap font, create that wglUseFontBitmaps( *hDC, //Device Context to get the font from 32, //Starting character we want to use 96, //How many characters to create base); //Start point of our display lists //Since this font type doesn't retrieve glyph metrics, it can be handy to retrieve some character info anyway GetCharWidth32(*hDC, 0, 255, info.charWidths); }else if (info.type == DIZ_FONT_OUTLINE) { //Or if we want an Outline font, create that wglUseFontOutlines( *hDC, //Device Context to get the font from 0, //Start character 255, //Number of characters to create base, //Starting display list info.deviation, //Our deviation from the true outline info.thickness, //Thickness (Z-direction) of font info.outlineType, //Type of outline to create gmf); //GMF info array } //Now that we're done, set the Device's font back to whatever it was before SelectObject(*hDC, oldFont); //Then delete the object we created DeleteObject(font); //And exit return true; }
void SetupRC(HDC hDC) { // Setup the Font characteristics HFONT hFont; GLYPHMETRICSFLOAT agmf[128]; // Throw away LOGFONT logfont; logfont.lfHeight = -10; logfont.lfWidth = 0; logfont.lfEscapement = 0; logfont.lfOrientation = 0; logfont.lfWeight = FW_BOLD; logfont.lfItalic = FALSE; logfont.lfUnderline = FALSE; logfont.lfStrikeOut = FALSE; logfont.lfCharSet = ANSI_CHARSET; logfont.lfOutPrecision = OUT_DEFAULT_PRECIS; logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; logfont.lfQuality = DEFAULT_QUALITY; logfont.lfPitchAndFamily = DEFAULT_PITCH; strcpy(logfont.lfFaceName,"Arial"); // Create the font and display list hFont = CreateFontIndirect(&logfont); SelectObject (hDC, hFont); //create display lists for glyphs 0 through 128 with 0.1 extrusion // and default deviation. nFontList = glGenLists(128); wglUseFontOutlines(hDC, 0, 128, nFontList, 0.0f, 0.5f, WGL_FONT_POLYGONS, agmf); DeleteObject(hFont); glEnable(GL_DEPTH_TEST); // Hidden surface removal glEnable(GL_COLOR_MATERIAL); glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0,GL_AMBIENT,whiteLight); glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight); glLightfv(GL_LIGHT0,GL_SPECULAR,specular); glLightfv(GL_LIGHT0,GL_POSITION,lightPos); glEnable(GL_LIGHT0); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glMaterialfv(GL_FRONT, GL_SPECULAR,specular); glMateriali(GL_FRONT,GL_SHININESS,128); }
OutFont::OutFont(HDC hdc) { /*this->m_listBase = glGenLists(256); this->m_font = CreateFont(-12,0,0,0, FW_BOLD,false,false,false, ANSI_CHARSET,OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Times New Roman"); if(this->m_font == NULL) MessageBox(NULL,"f**k font","error",MB_OK); SelectObject(this->m_hdc,this->m_font); wglUseFontOutlines(this->m_hdc,0,255,this->m_listBase, 0.0f,0.2f,WGL_FONT_POLYGONS, this->m_mf);*/ GLYPHMETRICSFLOAT m_mf[256]; this->m_listBase = glGenLists(256); this->m_font = CreateFont( -10, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Times New Roman"); SelectObject(hdc, this->m_font); wglUseFontOutlines( hdc, 0, 255, this->m_listBase, 0.0f, 0.2f, WGL_FONT_POLYGONS, m_mf); }
T3DFont::T3DFont(GLfloat _scale, const std::string &Name, int size, DWORD b, DWORD i, DWORD u, DWORD del, float dept) : BaseFont(_scale, Name, size, b, i, u, del) { GLYPHMETRICSFLOAT gmf[256]; HGDIOBJ prev = SelectObject(hDC, font); wglUseFontOutlines(hDC, 0, 255, lst_base, 0.0f, dept, WGL_FONT_POLYGONS, gmf); SelectObject(hDC, prev); for(register size_t k = 0; k < 256; ++k) widths[k] = gmf[k].gmfCellIncX; DeleteObject(font); font = NULL; return; }
bool Font3D::Create(HFONT hFont, View3D *view) { if(listbase != -1) Destroy(); // make it the calling thread's current rendering context wglMakeCurrent (view->hDC, view->hGLRC); // make the system font the device context's selected font HFONT hOldFont = (HFONT)SelectObject (view->hDC, hFont); GLYPHMETRICSFLOAT agmf[256]; listbase = glGenLists(256); wglUseFontOutlines(view->hDC, 0, 256, listbase, 0.0f, 0.0f, WGL_FONT_POLYGONS, agmf); SelectObject(view->hDC, hOldFont); return true; }
unsigned int COpenGL::CreateVectorFont(const char *pszFontName, int height, GLYPHMETRICSFLOAT *pGlyphMetrics) { // Here we generate the lists for each character we want to use. UINT fontListID = glGenLists(256); // Generate the list for the font // Now we actually need to create the font. We use a windows function called: // CreateFont() that returns a handle to a font (HFONT). Our CreateOpenGLFont() // function allows us to pass in a name and height. For simplistic reasons, I left // other options out, but feel free to add them to your function (like bold, italic, width..) HFONT hFont = CreateFont(height, // Our desired HEIGHT of the font 0, // The WIDTH (If we leave this zero it will pick the best width depending on the height) 0, // The angle of escapement 0, // The angle of orientation FW_BOLD, // The font's weight (We want it bold) FALSE, // Italic - We don't want italic FALSE, // Underline - We don't want it underlined FALSE, // Strikeout - We don't want it strikethrough ANSI_CHARSET, // This is the type of character set OUT_TT_PRECIS, // The Output Precision CLIP_DEFAULT_PRECIS, // The Clipping Precision ANTIALIASED_QUALITY, // The quality of the font - We want anitaliased fonts FF_DONTCARE|DEFAULT_PITCH, // The family and pitch of the font. We don't care. pszFontName); // The font name (Like "Arial", "Courier", etc...) // Now that we have created a new font, we need to select that font into our global HDC. // We store the old font so we can select it back in when we are done to avoid memory leaks. SelectObject(m_hDC, hFont); // This function does the magic. It takes the current font selected in // the hdc and makes bitmaps out of each character. These are called glyphs. // The first parameter is the HDC that holds the font to be used. // The second parameters is the ASCII value to start from, which is zero in our case. // The third parameters is the ASCII value to end on (255 is the last of the ASCII values so we minus 1 from MAX_CHARS) // The last parameter is the base pointer for the display lists being used. This should be 1. BOOL b = wglUseFontOutlines(m_hDC, 0, 255, fontListID, 0, 0, WGL_FONT_POLYGONS, pGlyphMetrics ); // Builds 255 bitmap characters DeleteObject(hFont); return fontListID; // Return the ID to the display list to use later }
void Font::init(HDC dc, const char *fontname, unsigned int uID) { //pSys->Active(); //* LOGFONT lf; if (fontname == NULL) { fontname = "Times New Roman"; } ZeroMemory(&lf, sizeof(lf)); lf.lfHeight = 20; strncpy(lf.lfFaceName, fontname, 32); switch (uID) { case IDM_BOLD: lf.lfWeight = FW_HEAVY; break; case IDM_ITALIC: lf.lfItalic = TRUE; break; case IDM_UNDERLINE: lf.lfUnderline = TRUE; break; } HFONT font = CreateFontIndirect(&lf); SelectObject(dc, font);//GetStockObject(SYSTEM_FIXED_FONT)); if (!wglUseFontOutlines(dc, 0, 128, base, 0.0f, 0.1f, WGL_FONT_LINES, agmf)) { // create the bitmap display lists // we're making images of glyphs 0 thru 255 // the display list numbering starts at 1000, an arbitrary choice if (!wglUseFontBitmaps(dc, 0, 128, base)) { MessageBox(0, fontname, "Failed to load font:", MB_OK); } } DeleteObject(font); }
GLvoid Print3DFont::BuildFont(GLvoid) { if (true == m_usingTex) m_tex.LoadTexture("mingzhuta.bmp"); m_base = glGenLists(256); GenFont(); //3D字体只能显示TrueType字体! ApplyFont(); wglUseFontOutlines( m_hDC, //设置当前窗口设备描述表的句柄 0, //用于创建显示列表字体的第一个字符的ASCII值 255, //字符数 m_base, //一个显示列表的名称 0.0f, //字体的光滑度,越小越光滑,0.0为最光滑的状态 0.2f, //在z方向突出的距离 WGL_FONT_POLYGONS, //使用多边形来生成字符,每个顶点具有独立的法线 m_gmf); //一个接收字形度量数据的数组的地址,每个数组元素用它对应的显示列表字符的数据填充 DestroyFont(); }
//============================================================================== void CGL_Font::CalcFontOutlines( HDC hDC, int iFillFlag ){ HFONT hFont; int iFillMode; iFillMode = iFillFlag ? WGL_FONT_POLYGONS : WGL_FONT_LINES; glDeleteLists(c_iDisplList0, N_FONT_CHARS); c_iDisplList0 = glGenLists(N_FONT_CHARS); // Get new range of display lists hFont = CreateFontIndirect(&c_tLogFont); // Windows create font SelectObject (hDC, hFont); // Windows call wglUseFontOutlines(hDC, 0, // first displ. list index N_FONT_CHARS, // N displ. lists, one list per char c_iDisplList0, // first GL's displ. list ID to use 0.0f, // maximum deviation 0 = precise 0.0f, // extrusion. makes font 3-D. 0 = flat iFillMode, // WGL_FONT_POLYGONS or WGL_FONT_LINES m_atGlyphMetrics); // save sizes here DeleteObject(hFont); // done with Windows font, we'll use display lists from now on }
void CVisText::BuildFont() // Build Our Bitmap Font { HFONT font; // Windows Font ID // CREATE FONT font = CreateFont( -1*20, // Height Of Font (not sure what this means) 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle fontWeight, // Font Weight fontItalic, // Italic fontUnderline, // Underline FALSE, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch fontName); // Font Name SelectObject(hDC, font); // Selects The Font We Just Created // CREATE FONT DISPLAY LISTS listBase = glGenLists(256); // Storage For 256 Characters int format = Fill ? WGL_FONT_POLYGONS : WGL_FONT_LINES; wglUseFontOutlines( hDC, // Select The Current DC 0, // Starting Character 255, // Number Of Display Lists To Build listBase, // Starting Display Lists 0.0f, // Deviation From The True Outlines 0.2f, // Font Thickness In The Z Direction format, // Use Polygons, Not Lines fontGMF); // Address Of Buffer To Recieve Data }
bool Font::Init(std::string fontname) { std::string mes("Generated Font "); mes += fontname.c_str(); m_engine->GetConsole()->Print(mes); m_base = glGenLists(256); m_font = CreateFont( -12 , 0 , 0 , 0 , FW_NORMAL , FALSE , FALSE , FALSE , ANSI_CHARSET , OUT_TT_PRECIS , CLIP_DEFAULT_PRECIS , ANTIALIASED_QUALITY , FF_DONTCARE | DEFAULT_PITCH , LPCSTR(fontname.c_str()) ); SelectObject(m_engine->m_hDC, m_font); wglUseFontOutlines( m_engine->m_hDC , 0 , 255 , m_base , 0.0f , 0.0f , WGL_FONT_POLYGONS , glyfs ); return true; }
Font::Font(char *name) { GLYPHMETRICSFLOAT agmf[256]; HFONT font; font = CreateFont( -50, // Height Of Font 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch name); // Font Name SelectObject(hDC, font); // Selects The Font We Created base = glGenLists(256); // try use true type // generate lists wglUseFontOutlines( hDC, // Select The Current DC 0, // Starting Character 255, // Number Of Display Lists To Build base, // Starting Display Lists 0.0f, // Deviation From The True Outlines 0.0f, // Font Thickness In The Z Direction WGL_FONT_POLYGONS, // Use Polygons, Not Lines agmf); // Address Of Buffer To Recieve Data // free hdc etc }
bool CText::BuildOutlineFont(const char *name, int size, bool bold, bool italic, bool underline, bool strikeout, float thickness) { if (loaded) { Free(); } UseFT=false; GLYPHMETRICSFLOAT gmf[NUM_CHARS]; HFONT font; listbase=glGenLists(NUM_CHARS); if (listbase) { HDC hDC=GetDC(CSettings::hwnd); // size=-MulDiv(size,GetDeviceCaps(hDC,LOGPIXELSY),72); size=-size; // size dont depend on system font size if (hDC) { font=CreateFont(size, // Height Of Font 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle bold?FW_BOLD:FW_NORMAL, // Font Weight italic, // Italic underline, // Underline strikeout, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch name); // Font Name if (font) { HGDIOBJ OldObj=SelectObject(hDC,font); loaded=(wglUseFontOutlines( hDC, // Select The Current DC 0, // Starting Character NUM_CHARS, // Number Of Display Lists To Build listbase, // Starting Display Lists 0.0f, // Deviation From The True Outlines thickness, // Font Thickness In The Z Direction WGL_FONT_POLYGONS, // Use Polygons, Not Lines gmf)!=0); // Address Of Buffer To Recieve Data if (loaded) { for (int i=0;i<NUM_CHARS;i++) { charsize[i][0]=gmf[i].gmfCellIncX; charsize[i][1]=gmf[i].gmfCellIncY; } charheight=(float)size; } SelectObject(hDC,OldObj); DeleteObject(font); } ReleaseDC(CSettings::hwnd,hDC); } } if (!loaded) { Free(); } return loaded; }
//#include "debugprint.h" WinFontStruct *WinFontCreate(char* fontname, char style, char size) { HFONT font; // Windows Font ID GLuint base; GLYPHMETRICSFLOAT gmf[256]; base = glGenLists(256); // Storage For 256 Characters // Height //By putting a minus, we're telling windows to find us a font based on the CHARACTER height. //If we use a positive number we match the font based on the CELL height. // Width //Then we specify the cell width. You'll notice I have it set to 0. //By setting values to 0, windows will use the default value. //You can play around with this value if you want. Make the font wide, etc. // Angle //Angle of Escapement will rotate the font. Orientation Angle quoted from MSDN help //Specifies the angle, in tenths of degrees, between each character's base line and //the x-axis of the device. //Unfortunately I have no idea what that means :( // Weight //Font weight is a great parameter. You can put a number from 0 - 1000 or you can use //one of the predefined values. FW_DONTCARE is 0, FW_NORMAL is 400, FW_BOLD is 700 //and FW_BLACK is 900. There are alot more predefined values, but those 4 give some //good variety. The higher the value, the thicker the font (more bold). // Style //Italic, Underline and Strikeout can be either TRUE or FALSE. Basically if underline //is TRUE, the font will be underlined. If it's FALSE it wont be. Pretty simple :) // Charset //Character set Identifier describes the type of Character set you wish to use. //There are too many types to explain. CHINESEBIG5_CHARSET, GREEK_CHARSET, RUSSIAN_CHARSET, //DEFAULT_CHARSET, etc. ANSI is the one I use, although DEFAULT would probably work //just as well. //If you're interested in using a font such as Webdings or Wingdings, you need to use //SYMBOL_CHARSET instead of ANSI_CHARSET. // Precision //Output Precision is very important. It tells Windows what type of character set //to use if there is more than one type available. OUT_TT_PRECIS tells Windows that //if there is more than one type of font to choose from with the same name, select //the TRUETYPE version of the font. Truetype fonts always look better, especially //when you make them large. You can also use OUT_TT_ONLY_PRECIS, which ALWAYS trys //to use a TRUETYPE Font. // Clipping Precision //is the type of clipping to do on the font if it goes outside the clipping region. //Not much to say about this, just leave it set to default. // Output Quality //is very important.you can have PROOF, DRAFT, NONANTIALIASED, DEFAULT or ANTIALIASED. //We all know that ANTIALIASED fonts look good :) Antialiasing a font is the same effect //you get when you turn on font smoothing in Windows. It makes everything look less jagged. // Family and Pitch //Next we have the Family and Pitch settings. For pitch you can have DEFAULT_PITCH, //FIXED_PITCH and VARIABLE_PITCH, and for family you can have FF_DECORATIVE, FF_MODERN, //FF_ROMAN, FF_SCRIPT, FF_SWISS, FF_DONTCARE. Play around with them to find out what //they do. I just set them both to default. // Font name //Finally... We have the actual name of the font. Boot up Microsoft Word or some other //text editor. Click on the font drop down menu, and find a font you like. To use the //font, replace 'Comic Sans MS' with the name of the font you'd rather use. font = CreateFont( -12, // Height Of Font 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle (style & WINFONT_BOLD) ? FW_BOLD : FW_DONTCARE, // Font Weight style & WINFONT_ITALIC, // Italic style & WINFONT_UNDERLINE, // Underline style & WINFONT_STRIKEOUT, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch fontname); // Font Name if (!font) { MessageBox(HWND_DESKTOP, "Failed to create font.", 0,0); return NULL; } HDC hDC = CreateCompatibleDC(GetDC(HWND_DESKTOP)); //"DISPLAY", NULL, NULL, NULL); if (!hDC) { MessageBox(HWND_DESKTOP, "Failed to create font.", 0,0); return NULL; } SelectObject(hDC, font); // Selects The Font We Created //Now for the new code. We build our Outline font using a new command wglUseFontOutlines. //We select our DC, the starting character, the number of characters to create and the //'base' display list value. All very similar to the way we built our Bitmap font. //That's not all however. We then set the deviation level. The closer to 0.0f, the //smooth the font will look. After we set the deviation, we get to set the font //thickness. This describes how thick the font is on the Z axis. 0.0f will produce //a flat 2D looking font and 1.0f will produce a font with some depth. //The parameter WGL_FONT_POLYGONS tells OpenGL to create a solid font using polygons. //If we use WGL_FONT_LINES instead, the font will be wireframe (made of lines). //It's also important to note that if you use GL_FONT_LINES, normals will not be //generated so lighting will not work properly. //The last parameter gmf points to the address buffer for the display list data. wglUseFontOutlines( hDC, // Select The Current DC 0, // Starting Character 255, // Number Of Display Lists To Build base, // Starting Display Lists 1.0f, // Deviation From The True Outlines 0.0f, // Font Thickness In The Z Direction WGL_FONT_POLYGONS, // Use Polygons, Not Lines gmf); // Address Of Buffer To Recieve Data //wglUseFontBitmaps (hDC, 0, 255, base); DeleteObject(font); DeleteDC(hDC); WinFontStruct *font_struct; font_struct = (WinFontStruct*)malloc(sizeof(WinFontStruct)); font_struct->base = base; memcpy(font_struct->gmf, gmf, sizeof(gmf[0])*256); return font_struct; }
// // Constructor // COutlineFont::COutlineFont( const TDesc& Desc, float Deviation, float Extrusion, UINT FirstGlyph, UINT GlyphsCount ): CFont( GlyphsCount ), m_Height( 0 ) { // // Non-portable codepath. // #ifdef _WIN32 HDC DC = wglGetCurrentDC(); if (!DC) throw Sys::CException( this, "::COutlineFont() : Failed to get current DC." ); LOGFONT lf; ZeroMemory( &lf, sizeof( LOGFONT ) ); lf.lfHeight = Desc.Height; lf.lfWidth = Desc.Width; lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfWeight = Desc.Weight; lf.lfItalic = Desc.Italic ? TRUE : FALSE; lf.lfUnderline = Desc.Underline ? TRUE : FALSE; lf.lfStrikeOut = FALSE; lf.lfCharSet = Desc.CharSet; lf.lfOutPrecision = Desc.OutputPrecision; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = Desc.Quality; lf.lfPitchAndFamily = Desc.PitchAndFamily; // FF_DONTCARE | DEFAULT_PITCH wcscpy( lf.lfFaceName, Desc.FaceName ); HFONT Font, OldFont; Font = CreateFontIndirect( &lf ); if (!Font) throw Sys::CException( this, "::COutlineFont() : Failed to create font." ); OldFont = (HFONT)SelectObject( DC, Font ); try { if (!wglUseFontOutlines( DC, FirstGlyph, GlyphsCount, m_ListBase, Deviation, Extrusion, WGL_FONT_POLYGONS, NULL )) throw Sys::CException( this, "::COutlineFont() : Failed to create glyph outlines." ); TEXTMETRIC Metrics; if (!GetTextMetrics( DC, &Metrics )) throw Sys::CException( this, "::COutlineFont() : Failed to get text metrics for selected font." ); m_Height = Metrics.tmHeight; } catch (const Sys::CException& Ex) { SelectObject( DC, OldFont ); DeleteObject( Font ); throw Ex; } SelectObject( DC, OldFont ); DeleteObject( Font ); #elif defined (__linux__) #endif // _WIN32 }