4

我使用 lwjgl 已经有一段时间了,最​​近我决定从固定功能管道切换到着色器。所以,当我开始我的程序时,我首先设置了 ContextAttrib(3, 2),所以我将使用 GL 3.2+。问题是当我打开更高版本的 GL 时,许多功能变得不受支持。在切换到更高的 GL 之前,我使用 Slick 的字体 (TrueTypeFont) 来渲染我需要的文本,但现在 TrueTypeFont 的 drawString 方法本身具有不受支持的功能。我试图用谷歌搜索解决方案,但没有任何结果。

有谁知道在使用 GL 3.2+ 版或其他库时是否可以使用 slick-util 库渲染文本?或有关该主题的任何链接。我将不胜感激任何帮助或建议。

编辑:启动 OpenGL 3.2 和更新版本的代码形成了 wiki 上的教程

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 或任何其他固定函数管道函数如 GL11.glMatrixMode(GL11.GL_PROJECTION); 上调用 drawString 时出现的异常:

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)

谢谢。

4

1 回答 1

0

A similar question popped up on the GameDevSE as well you might want for check it out here

Citing:

It sounds like you probably didn't actually request an appropriately-versioned OpenGL context (that is, one with 3.2 support). To do so, you must provide context attributes requesting the desired version when you call 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);
}
于 2014-10-11T21:36:23.247 回答