I recently started using LWJGL in my java programs for the graphics. I'm currently working on a simple game, which I make, to get better at this kind of programming. I ran into some trouble when adding textures to my 2D game.

To show my problem, I have made a simple program which shows one quad with a texture. This is how the texture looks:


However my program shows it like this:


You see the right and the bottom have some strange line hanging there. the shown picture is 100x100 from the top left to the little pixel right down.

The code used for drawing this is:

   GL11.glVertex2f(100, 200);
   GL11.glVertex2f(200, 200);
   GL11.glVertex2f(200, 100);
   GL11.glVertex2f(100, 100);

This code is called before drawing:

    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GL11.glOrtho(0, width, 0, height, -1, 1);

When I use


so 0.9f instead of 1.0f the weird lines don't appear. But that's no real solution because I want to use the whole texture not 90% of it.

I hope I did not ask something which has been asked before, I really couldn't find I using google, it is however quite hard to think of the right search words.

  • 1
    \$\begingroup\$ You might have to set your texture repeat mode to clamp. \$\endgroup\$
    – Tetrad
    May 8 '12 at 19:28
  • \$\begingroup\$ UV really run (0..1], which is really 0..1-(1/texwidth) if I recall correctly. \$\endgroup\$ May 8 '12 at 22:06

You should set your texture's wrap S and T modes to GL_CLAMP_TO_EDGE. This is done with the glTexParameter set of functions. Something like this:


Or the LWJGL equivalent to this.

You should call this when you're creating the texture (after your call to glTexImage2D), not when you're using it.

Also, don't forget to call it with GL_TEXTURE_WRAP_T too.

  • \$\begingroup\$ GL11.glTexParameteri(GL11.GL_TEXTURE_2D,GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D,GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); Might do the same, where exactly do I have to call it? \$\endgroup\$
    – GWigWam
    May 8 '12 at 19:57
  • \$\begingroup\$ @GWigWam: "You should call this when you're creating the texture (after your call to glTexImage2D), not when you're using it." \$\endgroup\$ May 8 '12 at 22:07
  • \$\begingroup\$ texture1 = TextureLoader.getTexture("PNG",ResourceLoader.getResourceAsStream("img/Test.png")); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); It's quite hard to enter code into the reply thing... After this code Render() is called (That's the firs piece of code in the orrigional post. Did I place it wrongly? The problem isn't solved! It still looks ugly. \$\endgroup\$
    – GWigWam
    May 8 '12 at 22:39
  • \$\begingroup\$ @GWigWam: "It's quite hard to enter code into the reply thing..." That's because this is not a forum. If you need to change your question, then you change it. In any case, I don't know what TextureLoader.getTexture does; is that your code or someone else's? \$\endgroup\$ May 8 '12 at 23:46
  • \$\begingroup\$ TextureLoader.getTexture saves a texture form a file (img/Test.png) in a Texture variable called texture1. \$\endgroup\$
    – GWigWam
    May 9 '12 at 9:02

The problem is fixed now, the WRAP_S wasn't the solution. It is the size of the image a 100x100 image shows this weird bug, but a 128x128 does not. 500x500 does not work 512x512 does.

Thanks to Nicol Bolas for trying to help, I would like to +rep, but I can't. Thanks for the support!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.