Advertisement

Combining Lesson 13 and 17, Text always black. -FIXED-

Started by January 30, 2005 01:47 AM
2 comments, last by Bad Maniac 19 years, 7 months ago
I've been taking the best bits from the bitmap font lessons 13 and 17, to create a windows font, and create a display list form it, just as in Lesson 13, but then set a 2D orth projection when printing it like lesson 17. I've got all that working without much trouble, but regardless of what color I set, the font is always displayed black, Doesn't matter how many glColor3f's I put in, where I put them, or what color I set, they get totally ignored. I've been looking at the source code from both the lessons, and I can't see any difference to my code. I set a perspective projection first, dra a lit textured rotating cube, and then I call the Print function, wich I've included below. The function resets all the matrices and so on, so I can see no problem with that, and the font does display at the right coordinates, just the wrong color, so please help.
GLvoid Print(GLuint x, GLuint y, const char *fmt, ...)	// Custom GL "Print" Routine
{
	char		text[1024];								// Holds Our String
	va_list		ap;										// Pointer To List Of Arguments

	if (fmt == NULL)									// If There's No Text
		return;											// Do Nothing

	glDisable(GL_DEPTH_TEST);							// Disables Depth Testing
	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glPushMatrix();										// Store The Projection Matrix
	glLoadIdentity();									// Reset The Projection Matrix
	glOrtho(0, screen_width, screen_height, 0, -1, 1);	// Set Up An Ortho Screen
	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
	glPushMatrix();										// Store The Modelview Matrix
	glLoadIdentity();									// Reset The Modelview Matrix

	glEnable(GL_BLEND);									// Enable Blending
	glRasterPos2i(x, y + font_height);					// Position The Text (0,0 - Bottom Left)

	va_start(ap, fmt);									// Parses The String For Variables
	    vsprintf(text, fmt, ap);						// And Converts Symbols To Actual Numbers
	va_end(ap);											// Results Are Stored In Text

	glPushAttrib(GL_LIST_BIT);							// Pushes The Display List Bits
	glListBase(base);									// Sets The Base Character to 0
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	// Draws The Display List Text

	glPopAttrib();										// Pops The Display List Bits

	glDisable(GL_BLEND);

	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glPopMatrix();										// Restore The Old Projection Matrix

	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
	glPopMatrix();										// Restore The Old Projection Matrix

	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
}


[Edited by - Bad Maniac on January 30, 2005 5:13:25 AM]
JRA GameDev Website//Bad Maniac
Where exactly are you setting the glColor3f's at? I would try it before the glCallLists is called first.

If that does not work, take a look at the "glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);" function. It could be setting the color to black by default, so when you are calling it, it always sets it to the wrong color.

If you are using 2D and 3D fonts - and one of them uses texturing, you will need to disable GL_TEXTURE_2D, then draw the font, then re-enable it. Give that a try as well.

Those are just a few things I can think of off the top of my head. Let us know if any work.

- Drew
Advertisement
Neither of those things worked I'm afraid, doesn't matter where I set the color, the text is still rendered solid black. Here's the BuildFont code, pretty much unedited form NeHe 13 except I use all 256 characters to be able to use all the funky ascii chars.
GLvoid BuildFont(CHAR *font_name, INT char_height)		// Build Our Bitmap Font{	HFONT	font;										// Windows Font ID	HFONT	oldfont;									// Used For Good House Keeping	font = CreateFont(	-char_height,					// 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						font_name);						// Font Name	oldfont = (HFONT)SelectObject(hDC, font);           // Selects The Font We Want		base = glGenLists(256);								// Storage For 256 Characters	wglUseFontBitmaps(hDC, 0, 256, base);				// Builds 96 Characters Starting At Character 32	SelectObject(hDC, oldfont);							// Selects The Font We Want	DeleteObject(font);									// Delete The Font	font_height = char_height;							//Set the global font height}


I call the Print function in my RenderScene function, and set the color on the line just above where I call it.

Anyone got any ideas what's wrong? The NeHe tutorial works fine on it's own, but if I copy that into ym project even it displays the characters solid black...
JRA GameDev Website//Bad Maniac
FIXED.

When I disabled lighting I had been a bit too quick with the tab completion, heh. glDisable(GL_LIGHT1); instead of glDisable(GL_LIGHTING);

OOPS... My bad, it works like a charm now.
JRA GameDev Website//Bad Maniac

This topic is closed to new replies.

Advertisement