0

I've been working on a game with LWJGL and came to a weird problem. Every time I decide to hide the text my textures seem to unbind. Here's all the code that is invlolved

Below is the code inside my Text class.

public void draw() {
        for (TextData textData : textList) {
            drawString(textData.getX(), textData.getY(), textData.getText());
        }
    }

void drawString(int x, int y, String text) {
        for (String line : text.split("\n"))
            ttf.drawString( x, y += ttf.getHeight(), line);
    }

Now the code in the main class

if (Keyboard.isKeyDown(Keyboard.KEY_H)) {
                hideText = !hideText;
        }

if (!hideText) {
            text.draw();
        }

This is the result

http://i.stack.imgur.com/4Y9fk.png

http://i.stack.imgur.com/SUoOf.png

4

2 回答 2

0

When text is drawn an image is bound to draw the text, i'm guessing that usually lwjgl/slick saves the current texture when drawing text and then rebinds it after. I would guess that it might be a bug where when hidden it doesn't rebind the texture but still binds another texture?

于 2013-11-02T22:16:39.687 回答
0

After careful consideration of my code I found out my Entity class was calling glBindTexture(GL_TEXTURE_2D, 0); while it was being drawn and drawing the text was enabling it again. Adding glBindTexture(GL_TEXTURE_2D, 1); at the end of my Entity drawing code fixed the problem. Thanks to the comments for helping me figure out the issue.

于 2013-11-05T05:57:30.093 回答