2
\$\begingroup\$

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?

\$\endgroup\$
2
\$\begingroup\$

Slick-util depends on deprecated API that is not available anymore with the latest version of lwjgl2. You could try to enable deprecated APIs when you create the context, but LWJGL2 is old. If you just started, you should switch to the newer and currently supported LWJGL3.

I don't know whether this is the best solution for LWJGL3, but here's a tutorial I found for LWJGL3: https://github.com/SilverTiger/lwjgl3-tutorial/wiki/Fonts

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.