The texture is not stretched properly. Why is this happening?

I use the LWJGL and Slick frameworks to load textures into my OpenGL application.

I am using this image: Japanese flag using for texture

And this code for importing and using 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 is as follows: Texture not stretching to the vertex-parameters

I do not use any special settings like GL_REPEAT or anything like that. What's happening? How to make the texture fill the given vertices?

+3
source share
3 answers

It seems that the texture becomes soft to the nearest strength of two. There are two solutions here:

  • Stretch the texture to the nearest power of two.
  • 1.0f textureWidth/nearestPowerOfTwoWidth textureHeight/nearestPowerOfTwoHeight.

LWJGL, . .

+8

, , . Slick2D, , ( : Texture.java TextureLoader.java TextureLoader get2Fold, , / . , --, , fold; (= ), "" , - , , ( ), . "" : GL11.glTexImage2D (target, 0, dstPixelFormat, get2Fold (bufferedImage.getWidth()), get2Fold (bufferedImage.getHeight()), 0, srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer); 4- = , 5 = . / IMAGE, . , , . , , .

+1

Hope this link is helpful.

http://www.lwjgl.org/wiki/index.php?title=Slick-Util_Library_-_Part_1_-_Loading_Images_for_LWJGL

looks very similar to what you are doing here.

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+texture.getTextureHeight());
GL11.glTexCoord2f(0,1);
GL11.glVertex2f(100,100+texture.getTextureHeight());
GL11.glEnd();
0
source