Hello,
I shortly started to use slick-util. Now I am trying to draw a string into the opengl window. I tried it both of the ways that are explained here
http://slick.cokeandcode.com/wiki/doku.php?id=truetype_font_supportUnfortunately both are bringing the same results. A rectangle in the specified color where the text should have been.
The code:
package spiel;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.TrueTypeFont;
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
public class TTFTest {
private static final String GAME_TITLE = "test";
private static final boolean fullscreen = false;
public static void main(String[] args)
throws LWJGLException, FontFormatException, IOException {
TrueTypeFont trueTypeFont;
// not included for brevity
initGL();
Font startFont = Font.createFont(Font.TRUETYPE_FONT,
new BufferedInputStream(new FileInputStream("verdana.ttf")));
Font baseFont = startFont.deriveFont(Font.PLAIN, 50);
trueTypeFont = new TrueTypeFont(baseFont, true);
System.out.println(trueTypeFont.toString());
while (true) {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
trueTypeFont.drawString(120.0f, 120.0f, "this is a test", Color.green);
Display.update();
if (Display.isCloseRequested()) {
System.exit(0);
}
}
}
private static void initGL()
{
try{
// Create a fullscreen window with 1:1 orthographic 2D projection (default)
Display.setTitle(GAME_TITLE);
Display.setFullscreen(fullscreen);
// Enable vsync if we can (due to how OpenGL works, it cannot be guarenteed to always work)
Display.setVSyncEnabled(true);
// Create default display of 640x480
Display.create();
} catch (Exception e)
{
}
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glViewport(0,0,640,480);
GL11.glOrtho(0, 640, 0, 480, 0, 25);
//GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_ALWAYS);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(GL11.GL_GREATER, 0);
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
}
I have the file verdana.ttf (copied from /usr/share/fonts/truetype/msttcorefonts/) in the project folder which is on the classpath.
Any ideas?? It is frustrating!
Thanks!