Hello everybody
Today I decided to experiment with the fonts functionality provided by the slick-library.
I keeped struggling with UnicodeFont/TrueTypeFont and ended up using AngelCodeFont.
Using Hiero it was pretty easy to convert my .ttf into a .fnt and the coresponding .png (if someone’s interested in the files: press_start_2p_4.png (warning: it’s white on white) and press_start_2p_4.fnt).
In my class I load the texture as follows:
font = new AngelCodeFont("font/press_start_2p_4.fnt", new Image("font/press_start_2p_4.png"));
Then I set up my orthographic view:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 200, 0, 200, -1, 1);
glMatrixMode(GL_MODELVIEW);
The opengl related part of my rendering cylce looks like this:
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
//draw background
glBegin(GL_QUADS);
glColor3f(red, green, blue);
glVertex2f(0, 0);
glColor3f(red, green, blue);
glVertex2f(200, 0);
glColor3f(red, green, blue);
glVertex2f(200, 200);
glColor3f(red, green, blue);
glVertex2f(0, 200);
glEnd();
glPopMatrix();
glPushMatrix();
//draw text
font.drawString(10, 380, "red: " + formatter.format(red));
font.drawString(10, 360, "green: " + formatter.format(green));
font.drawString(10, 340, "blue: " + formatter.format(blue));
glPopMatrix();
The variables red, green and blue are alterable by pressing certain keys on the numpad. That way you can adjust the background colour at runtime.
As you can see on the last few lines of code, I’m “printing” the current values of these variables onto the screen.
When I now start the application this is what I get:
https://dl.dropbox.com/u/911160/angelcode_rotated.JPG
I tried to do this, so the texture gets rotated in the buffer:
font = new AngelCodeFont("font/press_start_2p_4.fnt", new Image("font/press_start_2p_4.png", true));
But this doesn’t help at all, because the coordinates in the .ftn file are still the same and do not refer to the new character positions.
Has anyone any idea what could cause my problem?