SilentMrDave
SilentMrDave

Reputation: 1

Textures unbinding when text isn't drawn (LWJGL/Slick-util)

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

https://i.sstatic.net/4Y9fk.png

https://i.sstatic.net/SUoOf.png

Upvotes: 0

Views: 429

Answers (2)

SilentMrDave
SilentMrDave

Reputation: 1

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.

Upvotes: 0

OrangeMan
OrangeMan

Reputation: 692

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?

Upvotes: 0

Related Questions