Before this question is criticized for lack of research effort, please read the whole description, as I know there are other similar questions out there.
I am making a 3D game, and would like to put text on the screen (FPS counter, different stats for me while I am designing that won't go into the final product). I have followed this tutorial on how to use TrueTypeFont
fonts.
This is in my main game loop:
TrueTypeFont font = Text.prepareFont("WasterMaster10");
Color.white.bind(); //this is Line 163 in MainGameLoop.java
font.drawString(100, 50, Integer.toString(fps), Color.red);
And this is my preparation method in my Text
class:
public static TrueTypeFont prepareFont(String fontname) {
TrueTypeFont font = null;
// load font from a .ttf file
try {
InputStream inputStream = ResourceLoader.getResourceAsStream("res/" + fontname + ".ttf");
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);
awtFont = awtFont.deriveFont(24f); // set font size
font = new TrueTypeFont(awtFont, false);
} catch (Exception e) {
e.printStackTrace();
}
return font;
}
However, I keep getting this error:
Exception in thread "main" java.lang.IllegalStateException: Function is not supported
at org.lwjgl.BufferChecks.checkFunctionAddress(BufferChecks.java:58)
at org.lwjgl.opengl.GL11.glColor4f(GL11.java:893)
at org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer.glColor4f(ImmediateModeOGLRenderer.java:124)
at org.newdawn.slick.Color.bind(Color.java:182)
at engineTester.MainGameLoop.main(MainGameLoop.java:163)
I have been referring to this question and this question, as well as a lot of research on the web, but I still can't find why it won't work. The game works fine when the Color.white.bind()
and font.drawString(...)
lines are commented out. There are no syntax errors and the project compiles successfully. When I comment out just the Color.white.bind()
line, then the program compiles but throws an error at the font.drawString(...)
line during execution.
Does anyone know a better way to print text to the screen? Or is there a problem in my implementation?