1

So I am trying draw text to the screen with a custom font, which I have done. The issue comes when using textures at the same time.

I load my textures like this:

int Texture{

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

And my font like this

public static void load(float size) {

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

What is happening is some how the inputstreams have become 'mixed up' and the text I want is draw with the texture I loaded.

I load the font before the game loop from the Font.class and the textures are loaded from the class they are used in, which is called during the game loop.

I have googled the issue and cannot find anything. If you can understand me, thanks in advance.

Voight_
  • 11
  • 3

1 Answers1

0

Rather than the InputStreams becoming mixed up it is more likely it is the texture bindings. In your Texture class the following line is commented out:

//glBindTexture(GL_TEXTURE_2D, Texture);

This results in the texture image being loaded into whatever was previously bound to GL_TEXTURE2D replacing the previous texture.

You need to bind the texture before you can load an image into it with glTexImage2D

Aaron
  • 5,931
  • 4
  • 27
  • 31
  • I forgot to uncomment the code during me trying to smooth the issue out, sorry. Do you know how I can fix the issue I am having? – Voight_ May 06 '12 at 20:04
  • We need to seehiw you are binding the textures when you are rendering. Can you show this? – Aaron May 06 '12 at 20:49
  • This is the display list: `int buttonDisplayList = glGenLists(1); glNewList(buttonDisplayList, GL_COMPILE); { glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(xlocation, ylocation); glTexCoord2f(1, 0); glVertex2f((xlocation+width), ylocation); glTexCoord2f(1, 1); glVertex2f((xlocation+width), (ylocation-height)); glTexCoord2f(0, 1); glVertex2f(xlocation, (ylocation-height)); glEnd(); } glEndList();` – Voight_ May 07 '12 at 12:44
  • and this is the rendering part: 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); – Voight_ May 07 '12 at 12:45