Forseth11
Forseth11

Reputation: 13

LWJGL Texture not stretching to Quads

I have been trying for hours to get a Texture in LWJGL to stretch to a quad.

Here is the code I am using for the quad:

private static void renderLoad() {
    glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    texture.bind();

    glPushMatrix();{
    glBegin(GL_QUADS);
    {
        glTexCoord2f(0, 1);
        glVertex2f(0, 0); //Upper-left

        glTexCoord2f(1, 1);
        glVertex2f(Display.getWidth(), 0); //Upper-right

        glTexCoord2f(1, 0);
        glVertex2f(Display.getWidth(), Display.getHeight()); //Bottom-right

        glTexCoord2f(0, 0);
        glVertex2f(0, Display.getHeight()); //Bottom-left
    }
    glEnd();
    }glPopMatrix();
}

This is what the display looks like when I run it: http://gyazo.com/376ddb0979c55226d2f63c26215a1e12

I am trying to make the image expand to the size of the window. The Quad is at the size of the window, but the texture seems to not stretch.

Here is what it looks like if I do not use a texture and I simple make the quad a color: http://gyazo.com/65f21fe3efa2d3948de69b55d5c85424

If it helps here is my main loop:

glMatrixMode(GL_PROJECTION);
        glViewport(0, 0, displaySizeX, displaySizeY);
        glLoadIdentity();
        glOrtho(0, displaySizeX, 0, displaySizeY, 1, -1);
        glMatrixMode(GL_MODELVIEW);
        glEnable(GL_TEXTURE_2D);

        texture = loadLoadingImage();

        //This is the main loop for the game.
        while(!Display.isCloseRequested()){
            delta = getDelta();
            updateFPS();
            if(Display.wasResized()){
                displaySizeX = Display.getWidth();
                displaySizeY = Display.getHeight();
                glViewport(0, 0, displaySizeX, displaySizeY);
                glMatrixMode(GL_PROJECTION);
                glLoadIdentity();
                glOrtho(0, displaySizeX, 0, displaySizeY, -1, 1);
            }
            render();
            checkInput();
            Display.update();
            Display.sync(sync);
        }

        cleanUp();
        return true;

How do I make the image stretch to the quad?

Upvotes: 1

Views: 482

Answers (2)

Jherico
Jherico

Reputation: 29240

Perhaps something is modifying the texture matrix. You could try adding a

glMatrixMode(GL_TEXTURE);
glLoadIdentity();

to see if that affects anything.

Upvotes: 0

John Regard
John Regard

Reputation: 28

public void stretch() {
        Color.white.bind();
        texture.bind

        GL11.glBegin(GL11.GL_QUADS);
        GL11.glTexCoord2f(0,0);
        GL11.glVertex2f(100,100);
        GL11.glTexCoord2f(1,0);
        GL11.glVertex2f(100+texture.getTextureWidth(),100);
        GL11.glTexCoord2f(1,1);
        GL11.glVertex2f(100+texture.getTextureWidth(),100+character.getTextureHeight());
        GL11.glTexCoord2f(0,1);
        GL11.glVertex2f(100,100+texture.getTextureHeight());

        GL11.glEnd(); // all the 0's were originally 100 but it was off centered
    }

texture = TextureLoader.getTexture("PNG",ResourceLoader.getResourceAsStream("res/texture.png"));

Try using this. This is usually how I do this.

Upvotes: 1

Related Questions