所以我正在尝试使用我已经完成的自定义字体将文本绘制到屏幕上。同时使用纹理时会出现问题。
我像这样加载我的纹理:
诠释纹理{
try {
InputStream in = new FileInputStream(filelocation);
PNGDecoder decoder = new PNGDecoder(in);
ByteBuffer buffer = BufferUtils.createByteBuffer(4
* decoder.getWidth() * decoder.getHeight());
decoder.decode(buffer, decoder.getWidth() * 4, Format.RGBA);
buffer.flip();
in.close();
//glBindTexture(GL_TEXTURE_2D, Texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(),
decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,
buffer);
glBindTexture(GL_TEXTURE_2D, 0);
} catch (FileNotFoundException ex) {
System.err
.println("Textures are not in their correct location.");
Display.destroy();
System.exit(1);
} catch (IOException ex) {
System.err
.println("Textures are not in their correct location.");
Display.destroy();
System.exit(1);
}
}
我的字体是这样的
公共静态无效负载(浮动大小){
try {
InputStream inputStream = ResourceLoader.getResourceAsStream(filelocation);
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);
awtFont = awtFont.deriveFont(size);
fontname = new TrueTypeFont(awtFont, true);
} catch (Exception e) {
e.printStackTrace();
}
}
正在发生的事情是输入流如何“混合”,而我想要的文本是用我加载的纹理绘制的。
我在游戏循环之前从 Font.class 加载字体,纹理从它们使用的类加载,在游戏循环期间调用。
我已经用谷歌搜索了这个问题,但找不到任何东西。如果你能理解我,在此先感谢。