I have an OpenGL application that displays a 2D grid. I want to be able to label each cell in the grid with a letter.
Right now I am drawing text on each cell using the code based on this answer:
void drawLetter(double x, double y, double win_w, double win_h, char c) {
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, win_w, 0.0, win_h);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glColor3f(1.0, 1.0, 0.0); // Green
glRasterPos2i(x, y);
void * font = GLUT_BITMAP_8_BY_13;
glutBitmapCharacter(font, c);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
The problem I have is that the cells in the grid are much bigger than this font. I want the letters to be scaled to fill the entire cell. Ideally, I'd like to specify x, y, width, and height in window units, and scale the character to be those dimensions. However, I don't really know how to accomplish this. I've found some tutorials on the internet but they all seem to rely on external libraries; for various reasons I cannot use any external libraries.
Is there an easy way to accomplish this? I know there are also stroke fonts available but I still don't know how to accomplish the appropriate scaling.