4

I'm trying to implement 2D text rendering into my LWJGL game and have searched everywhere for a working solution, but keep getting the same error. I am currently trying to follow this tutorial. Here is the 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 org.newdawn.slick.TrueTypeFont.drawString(TrueTypeFont.java:363)
    at org.newdawn.slick.TrueTypeFont.drawString(TrueTypeFont.java:355)
    at guis.Gui.drawString(Gui.java:23)
    at engineTester.MainGameLoop.main(MainGameLoop.java:110)

and here is my Gui class:

package guis;

import java.awt.Font;

import org.newdawn.slick.TrueTypeFont;

public class Gui {

    private TrueTypeFont font;
    private Font awtFont;

    public Gui() {
        this.awtFont = new Font("Times New Roman", Font.BOLD, 24);
        this.font = new TrueTypeFont(awtFont, false);
    }

    public void drawString(int x, int y, String text) {
        font.drawString(x, y, text);
    }

}

Why is this error caused?

EDIT: Regarding this answer to another question: https://stackoverflow.com/a/26319508/5838494 I already did this and it does not work.

Richard Dallaway
  • 3,805
  • 1
  • 24
  • 37
  • Searching the web for `lwjgl IllegalStateException: Function is not supported` brings up _lots_ of hits. Did you try this? Did none of the information found there work for you? Please do basic research before posting here. – Jim Garrison Dec 16 '17 at 05:49
  • @JimGarrison none of them worked for me, an so that is why i asked here –  Dec 16 '17 at 19:07

2 Answers2

1

You need to set up your opengl version lower than 3.0, because functions used by TrueTypeFont have been removed in 3.x. Or you can take a look into opengl 3.x / 4.x Opengl3.3 if you do not have to support older opengl versions.

Angen
  • 400
  • 2
  • 10
  • I'm getting an error: Exception in thread "main" java.lang.IllegalArgumentException: Profiles are only supported on OpenGL version 3.2 or higher. at org.lwjgl.opengl.ContextAttribs.withProfileCore(ContextAttribs.java:188) at renderEngine.DisplayManager.createDisplay(DisplayManager.java:23) at engineTester.MainGameLoop.main(MainGameLoop.java:49) –  Dec 19 '17 at 21:59
1

The problem here is probably that you do something like

    public Gui theGui = new Gui();

in your main class I guess. Now, when you do this, the constructor is called and when you create your TrueTypeFont there, there is no OpenGL context yet, because the main class is also just being initialized, and hence the drawing fails because it has no OpenGL context.

You can try and change that to just a declaration like public Gui gui; and then, when you load your application, after you created the GL context, you assign the field with this.gui = new Gui();.

But I can only guess here because you do not have much code in your question. There might be other problems with this code, like incompatibility of the Slick library (Do you have the latest version, or better the version that's known to be compatible with your OpenGL version?), or similar.

Twometer
  • 1,070
  • 1
  • 14
  • 22