Advertisement

bitmap fonts

Started by June 14, 2003 10:48 AM
2 comments, last by leedude 21 years, 8 months ago
Hi all, im trying to implement bitmap fonts from NeHe tutorial 17 into my program and i''m using basically the same code, when i try and print it to screen it comes up as a white box where the text should be! just like if textures werent enabled or somthing (which they are ). i cant seem to find what is going wrong! i''d hoped someone else mite be able to see something that i am missing! here is the code im using to build the font from a texture (which is stored in a texture class i created, which works fine) and then to render the font to the screen.

bool BitmapFont::BuildFromFile(char *filename)
{
	float	cx;											// Holds Our X Character Coord

	float	cy;											// Holds Our Y Character Coord

	GLuint	loop;

	base=glGenLists(256);								// Creating 256 Display Lists

	//glBindTexture(GL_TEXTURE_2D, texture[0]);			// Select Our Font Texture

	font.UseBMPTexture(1);
	for (loop=0; loop<256; loop++)						// Loop Through All 256 Lists

	{

		cx=float(loop%16)/16.0f;						// X Position Of Current Character

		cy=float(loop/16)/16.0f;						// Y Position Of Current Character


		glNewList(base+loop,GL_COMPILE);				// Start Building A List

			glBegin(GL_QUADS);							// Use A Quad For Each Character

				glTexCoord2f(cx,1-cy-0.0625f);			// Texture Coord (Bottom Left)

				glVertex2i(0,0);						// Vertex Coord (Bottom Left)

				glTexCoord2f(cx+0.0625f,1-cy-0.0625f);	// Texture Coord (Bottom Right)

				glVertex2i(16,0);						// Vertex Coord (Bottom Right)

				glTexCoord2f(cx+0.0625f,1-cy);			// Texture Coord (Top Right)

				glVertex2i(16,16);						// Vertex Coord (Top Right)

				glTexCoord2f(cx,1-cy);					// Texture Coord (Top Left)

				glVertex2i(0,16);						// Vertex Coord (Top Left)

			glEnd();									// Done Building Our Quad (Character)

			glTranslated(10,0,0);						// Move To The Right Of The Character

		glEndList();									// Done Building The Display List


	}

	return true;

}

GLvoid BitmapFont::Print(GLint x, GLint y, int set, const char *fmt, ...)
{
	char text[256]; //holds the string

	va_list ap; //pointer to list of arguments


	if (fmt == NULL) //if theres no text

	return;

	va_start(ap, fmt); //parses the string for variables

	vsprintf(text, fmt, ap); //converts symbols to actual numbers

	va_end(ap); //restuls are stored in text


	if (set>1) //did user choose an invalid character set?

	{
		set = 1;
	}
	glEnable(GL_TEXTURE_2D);
	glLoadIdentity();
	glTranslated(x,y,0); //position the text (0,0) = bottom left

	glListBase(base-32+(128*set)); //choose the font set 1 or 0


	if (set==0) //if set 0 is being used then enlarge the font

	{
		glScalef(1.5f,2.0f,1.0f);
	}

	glCallLists(strlen(text),GL_UNSIGNED_BYTE, text); //write the text to the screen

	glDisable(GL_TEXTURE_2D);
}

if anyone could help that would be great. sorry if this is kinda long :S
Well...
1. U are using
char text[256]
and
glCallLists(strlen(text),GL_UNSIGNED_BYTE, text);
GL_UNSIGNED_BYTE... try to use GL_BYTE
2. The white box... try to put glGetError after glTexImage2D (or whatever texture function)
3. You should be sure the texture path is correct

PM


Times change...


Excuse my poor english!
PM Times change... Excuse my poor english!
Advertisement
Thanx for your reply PM,
its working now, it was something wrong in my texture class
also regarding ur post, what is the difference between using a GL_UNSIGNED_BYTE and a GL_BYTE?
unsigned bytes are 8bit without a sign. so there are 0 - 255. Signed bytes are 8bit numbers with a sign. there are -127 - 127.
I don''t know how the function is implemented but it could render some other chars...

PM


Times change...


Excuse my poor english!
PM Times change... Excuse my poor english!

This topic is closed to new replies.

Advertisement