0
votes

I'm currently working on a simple textured rectangle class using LWJGL (GL11). This is what I have so far in the draw method.

glEnable(GL_TEXTURE_2D);

color.bind();

glBegin(GL_QUADS);

t.bind();

if (centered)
{
    glTexCoord2d(0, 0);
    glVertex2d(x - (width / 2), y - (height / 2));
    glTexCoord2d(t.getWidth(), 0);
    glVertex2d(x + (width / 2), y - (height / 2));
    glTexCoord2d(t.getWidth(), t.getHeight());
    glVertex2d(x + (width / 2), y + (height / 2));
    glTexCoord2d(0, t.getHeight());
    glVertex2d(x - (width / 2), y + (height / 2));
}
else
{
    glTexCoord2d(0, 0);
    glVertex2d(x, y);
    glTexCoord2d(t.getWidth(), 0);
    glVertex2d(x + width, y);
    glTexCoord2d(t.getWidth(), t.getHeight());
    glVertex2d(x + width, y + height);
    glTexCoord2d(0, t.getHeight());
    glVertex2d(x, y + height);
}
glEnd();

glBindTexture(GL_TEXTURE_2D, 0);

glDisable(GL_TEXTURE_2D);

The problem is with the second to last line (glBindTexture(GL_TEXTURE_2D, 0)). If I leave this on, the image will display for a split second (probably one frame) and then turn solid white. If I comment this out, it will display, but always displays the last texture that was loaded. Any ideas?

1

1 Answers

0
votes

I think it's because you are binding your texture between the glBegin() and glEnd() calls. This is invalid. I'm guessing when you leave the glBindTexture(GL_TEXTURE_2D, 0) call off, then the binding is taking effect the next frame. Not sure why it would work for one frame, though.

You can use glGetError to see if there are any errors generated.