Skip to main content
gamedev.net
🔒 Locked

Font not rendering

Started by Samith Dec 30, 2004 at 3:43 PM 1 replies 1.3k views
Original Post
Samith
Samith
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();
		glLoadIdentity();
		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].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]
MARS_999
MARS_999
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...
Samith
Samith
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.