ERROR Drawing Texture in LWJGL

I have been using the code in the LWJGL wiki Space Invaders example to load the textures from BufferedImage. Here’s the code I have found to draw the texture.


public void drawTexture(Texture tex, float x, float y, float width, float height)
{
    glPushMatrix();
    tex.bind();

    glTranslatef(x, y, 0);

    glBegin(GL_QUADS);
    {
        glTexCoord2f(0, 0);
        glVertex2f(0, 0);

        glTexCoord2f(0, tex.getHeight());
        glVertex2f(0, height);

        glTexCoord2f(tex.getWidth(), tex.getHeight());
        glVertex2f(width, height);

        glTexCoord2f(tex.getWidth(), 0);
        glVertex2f(width, 0);
    }
    glEnd();

    glPopMatrix();
}

And I’m calling this to load the Texture.


TextureLoader texLoader = new TextureLoader();
Texture tex = texLoader.getTexture("resources/testTex.png");
drawTexture(tex, 0, 0, 100, 100);

This is the output.

And this is the original image.

The texture isn’t being drawn perfectly and it is even going to the top right corner.

How can I fix it?