Texture doesn't stretch properly. Why is this happening?

graphics, java, lwjgl, opengl, textures

Solution

It looks like the texture is getting padded out to the nearest power of two. There are two solutions here:

- Stretch the texture out to the nearest power of two.

- Calculate the difference between your texture's size and the nearest power of two and change the texture coordinates from `1.0f` to `textureWidth/nearestPowerOfTwoWidth` and `textureHeight/nearestPowerOfTwoHeight`.

There might also be some specific LWJGL method to allow for non-power-of-two textures, look into that.

Problem

I'm using LWJGL and Slick framework to load Textures to my OpenGL-application. I'm using this image: And this code to import and utilize the texture: ``` flagTexture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("japan.png")); ``` ...... ``` flagTexture.bind(); GL11.glColor3f(1.0f, 1.0f, 1.0f); GL11.glPushMatrix(); GL11.glTranslatef(0.0f, 0.0f, -10.0f); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex2f(0.0f, 0.0f); GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex2f(2.5f, 0.0f); GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex2f(2.5f, 2.5f); GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex2f(0.0f, 2.5f); GL11.glEnd(); GL11.glPopMatrix(); ``` But the end-result becomes this: I'm not using any special settings like GL_REPEAT or anything like that. Whats going on? How can I make the texture fill the given vertices?

Original source