Custom Bitmap Fonts

Started by
0 comments, last by sckoobs 21 years, 6 months ago
I have been doing tutorial 17 - Texture Fonts and have become stuck. I am trying to adopt the code to fit a 100x100 pixel bitmap with each character being 10x10 pixels. I have modified the build font function and is here in full:

void BuildFont()
{
	// x, y positions of character inside the font
	float charX, charY;

	// generate display lists
	base = glGenLists(100);

	// select the font texture
	glBindTexture(GL_TEXTURE_2D, fontTexture);

	// 
	for(int loop = 0; loop < 100; loop++)
	{
		// find the coordinate of the character we wish to build a quad for
		charX = float(loop % 10) / 10;
		charY = float(loop / 10) / 10;

		// start building a lisplay list for the character selected
		glNewList(base + loop, GL_COMPILE);

			// begin building the quad
			glBegin(GL_QUADS);
				
				// texture coord for bottom left
				glTexCoord2f(charX, 1 - charY - 0.1f);

				// quad coord bottom left
				glVertex2i(0, 0);

				// ----------------------------------

				// texture coord bottom right
				glTexCoord2f(charX + 0.1f, 1 - charY - 0.1f);

				// quad coord bottom right
				glVertex2i(10, 0);

				// ----------------------------------

				// texture coord top right
				glTexCoord2f(charX + 0.1f, 1 - charY);

				// quad coord top right
				glVertex2i(10, 10);

				// ----------------------------------

				// texture coord top left
				glTexCoord2f(charX, 1 - charY);

				// quad coord top left
				glVertex2i(0, 10);

			// finished building the character quad
			glEnd();

			// move to the right for the next character
			glTranslated(10, 0, 0);
		
		// finished building display list
		glEndList();
	}
}
  
Is my problem related to the fact that OpenGL or my graphics drivers can only load textures with dimentions of powers of 2? or is my code wrong? I haven't had problems with non ^2 textures before with my current card, can anyone suggest anything? Thanks, sckoobs [edited by - sckoobs on October 3, 2002 12:11:27 PM]
Advertisement
all textures in opengl must be powers of two, so 100x100 won''t work,
but 128x128 works. characters can be 10x10, just add black pixels to
your image so it is 128x128.

This topic is closed to new replies.

Advertisement