Bitmap Font

I need help getting a certain 16x16 area on a bitmap of my choice, preferably I want to have a variable that can change (0,1,2,3), so I can just wip up something using ascii to map character to point, and then will get that 16x16 area.

Currently when I change the texture coords, the smaller it is, the more zoomed in it is on the bottom left, the bigger it is, the more zoomed out it is, but when I make them different from each other it start slanting and doing weird stuff? What am I doing wrong and how do I only show one slot?

My code so far:


glPushMatrix();
		{
			glColor4f(0f, 0f, 0f, 1.0f);
			glTranslated(x,y,0);
			bitmap.bind();
			for(int i = 0; i < str.length(); i++){
				
				glBegin(GL_QUADS);
				{
					glTexCoord2f(0,0); glVertex2d(0, 0);
					glTexCoord2f(0.25f,0); glVertex2d(0, fontSize);
					glTexCoord2f(0.25f,0.25f); glVertex2d(fontSize, fontSize);
					glTexCoord2f(0,0.25f); glVertex2d(fontSize, 0);
				}
				glEnd();
			}
		}
		glPopMatrix();

Fontsize is the size its going to renderer, For my tests I passed it as 10.

Can you post pictures of your issue? I don’t entirely understand what your problem is.

Here is tutorial for very simple bitmap font.


public class Font {

	private static String chars = 
			  "ABCDEFGHIJKLMNO"
			+ "PQRSTUVWXYZ    "
			+ "0123456789     "
			+ ".,-+!':?/<>()\";";
	
	
	
	public static void draw(String mess, Screen screen, float x, float y, float size, Color color) {
		
		mess = mess.toUpperCase();
		mess = verify(mess);
		
		for(int i=0;i<mess.length();i++) {
			int index = chars.indexOf(mess.charAt(i));
			
			int xs = index % 15;
			int ys = index / 15 + 28;
			
			Sprite sprite=new Sprite(SpriteSheet.sheet, xs, ys, 8, 8);
			
			screen.render(x + i * size, y, size, size, sprite, color);
		}
		
	}
	
	private static String verify(String mess) {

		mess = mess.replace(". ", ".");
		mess = mess.replace(", ", ",");
		mess = mess.replace("'", "");
		
		return mess;
	}
	
}

Here is screen .render


public void render(float x, float y, float width, float height, Sprite sprite, Color color)
{
	float u0 = (float) (sprite.x * sprite.width) / sprite.texture.width;
	float v0 = (float) (sprite.y * sprite.height) / sprite.texture.height;

	float u1 = (float) ((sprite.x + 1) * sprite.width) / sprite.texture.width;
	float v1 = (float) ((sprite.y + 1) * sprite.height) / sprite.texture.height;

	GL11.glBegin(GL11.GL_QUADS);

	GL11.glColor4f(color.r, color.g, color.b, color.a);
	
	GL11.glTexCoord2f(u0, v0);
	GL11.glVertex2f(x, y);

	GL11.glTexCoord2f(u1, v0);
	GL11.glVertex2f(x + width, y);

	GL11.glTexCoord2f(u1, v1);
	GL11.glVertex2f(x + width, y + height);

	GL11.glTexCoord2f(u0, v1);
	GL11.glVertex2f(x, y + height);


	GL11.glEnd();
}


Watch this video: https://www.youtube.com/watch?v=62YVcYT4mSE