LWJGL 3.2.0+ 字体

4
我已经使用lwjgl工作了一段时间,最近决定从固定功能管线切换到着色器。所以,当我启动程序时,第一件事就是设置ContextAttrib(3, 2),这样我就可以使用GL 3.2+。问题是,当我切换到更高版本的GL时,很多函数变得不支持了。在切换到更高的GL之前,我使用Slick的字体(TrueTypeFont)来渲染所需的文本,但现在TrueTypeFont的drawString方法内部有一个不支持的函数。我尝试过谷歌搜索解决方案,但没有找到任何结果。
有人知道是否可能在使用GL版本3.2+或其他库的情况下使用slick-util库来渲染文本吗?或者有关这个主题的任何链接。我将非常感激任何帮助或建议。
编辑:从维基百科上的教程中获取启动openGL 3.2和更新版本的代码。
try
    {
        PixelFormat pixelFormat = new PixelFormat();
        ContextAttribs contextAtrributes = new ContextAttribs(3, 2)
            .withForwardCompatible(true)
            .withProfileCore(true);

        Display.create(pixelFormat, contextAtrributes);
    } catch (LWJGLException e){
        e.printStackTrace();
        return;
    }

使用OpenGL 3.2或更高版本时,您只能使用着色器。唯一的例外是在调用UnicodeFont或TrueTypeFont的drawString函数时出现,或者调用GL11.glMatrixMode(GL11.GL_PROJECTION)等其他固定功能管线函数时出现的情况。
Exception in thread "Thread-0" java.lang.IllegalStateException: Function is not supported
at org.lwjgl.BufferChecks.checkFunctionAddress(BufferChecks.java:58)
at org.lwjgl.opengl.GL11.glColor4f(GL11.java:881)
at org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer.glColor4f(ImmediateModeOGLRenderer.java:127)
at org.newdawn.slick.Color.bind(Color.java:182)
at org.newdawn.slick.UnicodeFont.drawDisplayList(UnicodeFont.java:443)
at org.newdawn.slick.UnicodeFont.drawString(UnicodeFont.java:551)
at org.newdawn.slick.UnicodeFont.drawString(UnicodeFont.java:559)
at org.newdawn.slick.UnicodeFont.drawString(UnicodeFont.java:555)
at application.Controller.render3D(Controller.java:163)
at Engine.Engine.renderScene3D(Engine.java:230)
at Engine.Engine.render(Engine.java:334)
at Engine.Engine.gameLoop(Engine.java:306)
at Engine.Engine.access$1(Engine.java:246)
at Engine.Engine$1.run(Engine.java:154)

谢谢。

我看到这个问题已经相对较旧了,你找到解决方案了吗? - skiwi
1个回答

0
在GameDevSE上也出现了类似的问题,你可能想要去查看一下这里
引用:
“听起来你可能没有实际请求适当版本的OpenGL上下文(即支持3.2的上下文)。为了做到这一点,在调用Display.create()时,必须提供请求所需版本的上下文属性。”
PixelFormat pixelFormat = new PixelFormat();
ContextAttribs contextAtrributes = new ContextAttribs(3, 2)
    .withForwardCompatible(true)
    .withProfileCore(true);

try {
      Display.setDisplayMode(new DisplayMode(320, 240));
      Display.setTitle("Version selection");
      Display.create(pixelFormat, contextAtrributes);
} catch (LWJGLException e) {
    e.printStackTrace();
    System.exit(-1);
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接