Using OpenGL Text Output with DIB Section
-
Hello, I am creating an outline font as below, and use it with PrintOutlineString, when i use these functions without DIB Section (which i use for printing) it works. However, when i use the DIBSection, i cannot display texts. May be a bit off-topic in this forum, however if anyone used both together and how? Thanks in advance. Bekir.
unsigned int CreateOutlineFont(char *fontName, int fontSize, float depth) { HFONT hFont; // windows font unsigned int base; base = glGenLists(256); // create storage for 96 characters if (stricmp(fontName, "symbol") == 0) { hFont = CreateFont(fontSize, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, SYMBOL_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, fontName); } else { hFont = CreateFont(fontSize, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, fontName); } if (!hFont) return 0; SelectObject((*m_dib.GetDC()), hFont); wglUseFontOutlines((*m_dib.GetDC()), 0, 255, base, 0.0f, depth, WGL_FONT_POLYGONS, gmf); /* SelectObject(m_hDC, hFont); wglUseFontOutlines(m_hDC, 0, 255, base, 0.0f, depth, WGL_FONT_POLYGONS, gmf); /**/ return base; } void PrintOutlineString(double x, double y, char *str) { float length = 0; if ((str == NULL)) return; // center the text for (unsigned int loop=0;loop<(strlen(str));loop++) // find length of text { length+=gmf[str[loop]].gmfCellIncX; // increase length by character's width } glPushMatrix(); glLoadIdentity(); glTranslatef(x,y,0.0f); // translate to center text //glScalef(0.25,0.25,0.25); // draw the text glPushAttrib(GL_LIST_BIT); glListBase(listBase); glCallLists(strlen(str), GL_UNSIGNED_BYTE, str); glPopAttrib(); glPopMatrix(); }