Java 涉及真字体和纹理LWJGL的问题

Java 涉及真字体和纹理LWJGL的问题,java,lwjgl,Java,Lwjgl,所以我尝试用自定义字体在屏幕上绘制文本,我已经完成了。同时使用纹理时会出现问题 我像这样加载纹理: 内部纹理{ try { InputStream in = new FileInputStream(filelocation); PNGDecoder decoder = new PNGDecoder(in); ByteBuffer buffer = BufferUtils.createByteBuffer(4

所以我尝试用自定义字体在屏幕上绘制文本,我已经完成了。同时使用纹理时会出现问题

我像这样加载纹理:

内部纹理{

        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);
        }
    }
我的字体是这样的

公共静态空隙荷载(浮子尺寸){

现在发生的事情是输入流如何变得“混乱”,我想要的文本是用我加载的纹理绘制的

我在游戏循环之前从font.class加载字体,纹理从它们使用的类加载,在游戏循环期间调用该类

我在谷歌上搜索了这个问题,什么也找不到。
如果您能理解我的意思,请提前感谢。

与其说输入流混淆,不如说是纹理绑定。 在纹理类中,注释掉以下行:

//glBindTexture(GL_TEXTURE_2D,纹理)

这将导致纹理图像加载到先前绑定到GL_TEXTURE2D的对象中,以替换先前的纹理


您需要先绑定纹理,然后才能使用glTexImage2D将图像加载到其中。抱歉,我在尝试解决问题时忘记取消对代码的注释。您知道如何解决我遇到的问题吗?我们需要查看渲染时您是如何绑定纹理的。您可以显示此内容吗?这是显示列表:
int,但是tonDisplayList=GlgenList(1);glNewList(按钮显示列表,GL_编译);{glBegin(GL_四边形);glTexCoord2f(0,0);glVertex2f(xlocation,ylocation);glTexCoord2f(1,0);glVertex2f((xlocation+width),ylocation);glTexCoord2f(xlocation+width),(xlocation+width));glTexCoord2f(0,1);glVertex2f这是渲染部分:glBindTexture(GL_TEXTURE_2D,buttonTexture);glColor4f(1f,1f,1f,(float)Math.sin(Math.toRadians(alpha));glCallList(buttonDisplayList));MyFont.render(xlocation+width/2-(label.length()*(size/5)),ylocation height/1.4f,label);
    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();
    }   
}