Font not rendering

This topic is 4734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Well, I'm about to my wit's end on this. It's pretty much based off NeHe's tutorial and some other sources. Using display lists for fonts is the only way I've ever seen it done, and it's not working out very well for me, at the moment. Basically, I have it set up so I can output text to the screen like a std::cout call. Like: font << "Hello thar! " << 123 << someObjectWhosGotOperatorsOverloadedToHandleThis; Here is what I think is the relevant code:
template<typename T> CFont& operator<<(T const& t) {
oss << t;
s = oss.str();

std::cout << s;
glPushMatrix();
glColor4f(r, g, b, a);
glTranslatef(0.0f, 0.0f, 1.0f);	// translate one unit into the screen
glRasterPos2f(xScreen + xMod, yScreen);

glPushAttrib(GL_LIST_BIT);
glListBase(base);
glCallLists(s.length(), GL_UNSIGNED_BYTE, s.c_str());
glPopAttrib();

glPopMatrix();

for(int i = 0; i < s.length(); i++) {
xMod += gmf[s[i]].gmfCellIncX;
}
return *this;
}


That is the font printing method. I know I'm getting the string right, because when I call std::cout << s; it shows whatever I send to the function, it's just the rendering part that isn't working at all, and I don't know why. I've used display lists to draw fonts tons of times and it's always worked for me. Oh, by the way, I'm using outline fonts. Here is my BuildFont() function if you want to look at that:
void CFont::BuildFont(const char* fontname, int size)
{
HFONT font;
HDC hDC;
base = glGenLists(256);

hDC = wglGetCurrentDC();

font = CreateFont(-size,
0,
0,
0,
FW_NORMAL,
false,
false,
false,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
FF_DONTCARE|DEFAULT_PITCH,
fontname);

SelectObject(hDC, font);

wglUseFontOutlines(hDC,
0,
255,
base,
0.0f,
0.2f,
WGL_FONT_POLYGONS,
gmf);
}


I don't know what else to show you guys, but if you need to see more code just ask and I'll post it. Thanks a lot for any help. UPDATE: Ok, I didn't notice before, but it actually *is* rendering. It's rendering it VERY small up in the top. It's not rendering it at size 48 like I want it to, it's rendering it smaller than 1 pixel, it's also upside down. (How do I know if it's upside down if it's smaller than a pixel you ask? I changed the projection so it would be way more zoomed in and I could see) It also keeps rendering it over and over in one long line (Like, instead of just saying "Hello!" it says "Hello!Hello!Hello!Hello!"). UPDATE THE SECOND: Fixed one problem, the position problem. Apparently glRasterPos doesn't work with outline fonts. Using glTranslate3f puts it in the right position. UPDATE THE THIRD: Solved the upside down-ity problem, now all that's left is the size problem and the drawing over and over problem. UPDATE THE FOURTH: Ok, using glScale I came up with a crappy hack solution to the size problem, now all that's left is the annoying problem where it keeps writing in a really long line, instead of writing in the same place it did during the previous loop. [Edited by - Samith on December 30, 2004 5:10:51 PM]

Share on other sites
You have to remember that you are actually rendering to polygons to display the text with this method and to resize the text you need to use glScale() or manually increase the polygon sizes yourself. Oh yeah I found that out to glRaster doesn't work with this method either due to the fonts are 3D and you need to use glTranslate instead...

Share on other sites
Thanks for the help, but I just figured it all out for myself :)

The reason why the font was rendering like "HelloHelloHello" instead of just "Hello" was due to the fact that I was not clearing the ostringstream after each call. So after the first time through, oss said "Hello", after time two, it said "HelloHello" because I hadn't cleared it. Also, std::ostringstream::clear() does NOT clear the stream, it clears the ERROR FLAGS, which I did not realize until this morning. To clear the oss I just go "oss.str("");" and everything works fine.

Thanks again for taking the time out to help me, though.

Share on other sites

This topic is 4734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628760
• Total Posts
2984542

• 12
• 25
• 12
• 10
• 17