LWJGL 3.2.0+字体

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

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

编辑:启动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上调用drawString时出现的exception,或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) 

谢谢。

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); }