我一直在使用带有 lwjgl 的漂亮 GUI,它运行良好,但我不知道如何让它使用我提供的字体;它似乎只能呈现默认字体。我已将带有 .fnt 文件的文件夹添加到运行时类路径(通过 eclipse),这样就不会发生“找不到资源”异常,但是当我运行程序时,任何使用我的字体的文本字段都不会' t 渲染。
这是源代码,它在左上角呈现两个文本字段,在中心呈现两个白色形状。除非我使用默认字体,否则右侧的文本字段不会呈现。
package game;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.opengl.*;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.builder.LayerBuilder;
import de.lessvoid.nifty.builder.ScreenBuilder;
import de.lessvoid.nifty.builder.TextBuilder;
import de.lessvoid.nifty.nulldevice.NullSoundDevice;
import de.lessvoid.nifty.renderer.lwjgl.input.LwjglInputSystem;
import de.lessvoid.nifty.renderer.lwjgl.render.LwjglRenderDevice;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.tools.TimeProvider;
public class NiftyWontUseMyFont {
private Nifty nifty;
private Screen screen;
private float[] WINDOW_DIMENSIONS = {640,480};
public NiftyWontUseMyFont() throws Exception{
//init display
Display.setDisplayMode(new DisplayMode(640,480));
Display.create();
//init nifty gui
LwjglInputSystem inputSystem = new LwjglInputSystem();
inputSystem.startup();
nifty = new Nifty(
new LwjglRenderDevice(),
new NullSoundDevice(),
inputSystem,
new TimeProvider());
// load default styles
nifty.loadStyleFile("nifty-default-styles.xml");
// load standard controls
nifty.loadControlFile("nifty-default-controls.xml");
screen = new ScreenBuilder("start") {{
layer(new LayerBuilder("baseLayer") {{
childLayoutHorizontal();
text(new TextBuilder("test"){{
font("aurulent-sans-16.fnt");
color("#f00f");
backgroundColor("#33af");
text("l33t");
}});
text(new TextBuilder("test2"){{
font("16-Jackash.fnt");//doesn't work with this external font
// font("aurulent-sans-16.fnt");//works with the default font
color("#f00f");
backgroundColor("#33af");
text("l33t");
}});
}});
}}.build(nifty);
nifty.gotoScreen("start");
//init opengl
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,640,480,0,1,-1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0,640,480);
glPushMatrix();
glPopMatrix();
while(!Display.isCloseRequested())
{
//render
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
glTexCoord2f(0,0);glVertex2i(400,400); //Upper left
glTexCoord2f(1,0);glVertex2i(450,400);//upper right
glTexCoord2f(1,1);glVertex2i(450,450);//bottom right
glTexCoord2f(0,1);glVertex2i(400,450);//bottom left
glEnd();
glBegin(GL_LINES);
glVertex2i(100,100);
glVertex2i(200,200);
glEnd();
nifty.update();
glPushMatrix();
glPushAttrib(GL_ALL_ATTRIB_BITS);
nifty.render(false);
glPopAttrib();
glPopMatrix();
Display.update();
Display.sync(60);
}
Display.destroy();
}
public static void main(String[] args) throws Exception {
new NiftyWontUseMyFont();
}
}