0
\$\begingroup\$

I tried a lot of things to fix texture bleeding, but nothing works. I don't want to add a transparent border around my textures, because I already got too many and it would take too much time and I can't do it with code because I'm loading textures with slick. My textures are seperate textures and they seem to wrap on the other side (texture bleeding).

Here are the textures that are "bleeding":

The bleeding texture

The head, body, arm and leg are seperate textures.

Here's the code I'm using to draw a texture:

public static void drawTextureN(Texture texture, Vector2f position, Vector2f translation, Vector2f origin,Vector2f scale,float rotation, Color color, FlipState flipState)
    {
        texture.setTextureFilter(GL11.GL_NEAREST);


        color.bind();
        texture.bind();


        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);

        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);

        GL11.glTranslatef((int)position.x, (int)position.y, 0);
        GL11.glTranslatef(-(int)translation.x, -(int)translation.y, 0);
        GL11.glRotated(rotation, 0f, 0f, 1f);

        GL11.glScalef(scale.x, scale.y, 1);

        GL11.glTranslatef(-(int)origin.x, -(int)origin.y, 0);

        float pixelCorrection = 0f;

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

        GL11.glEnd();

        GL11.glLoadIdentity();
    }

I tried a half pixel correction but it didn't make any sense because GL12.GL_CLAMP_TO_EDGE. I set pixelCorrection to 0, but it still wont work.

\$\endgroup\$
0

2 Answers 2

1
\$\begingroup\$

Texture must be a square with measurements of an exponent of two (16, 32, 64, 128, etc...), so re-size the file to one of those. I tend to use 1024 X 1024 for item textures. Otherwise LWJGL gets all messed up and the texture 'bleeds.'

\$\endgroup\$
0
\$\begingroup\$

Since you are drawing a single texture onto a single quad at a time, shouldn't the texture coordinates of all the vertices be either 0 or 1 (all 4 permutations of that for each of the 4 corners)? Texture coordinates range from 0 and 1, 0 being the start and 1 being the end of the texture in s and t.

Namely:

    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2f(0,0);

    GL11.glTexCoord2f(1,0);
    GL11.glVertex2f(texture.getTextureWidth(),0);

   // etc...
\$\endgroup\$
12
  • \$\begingroup\$ They >do< range from 0 to 1. \$\endgroup\$ Commented Sep 29, 2013 at 16:16
  • \$\begingroup\$ I mean, why are they not literally 0 and 1? \$\endgroup\$
    – Matt Jones
    Commented Sep 29, 2013 at 16:21
  • \$\begingroup\$ That was a half pixel correction try, which didn't make much sense because GL12.GL_CLAMP_TO_EDGE. \$\endgroup\$ Commented Sep 29, 2013 at 16:30
  • \$\begingroup\$ Are your texture dimensions powers of two by any chance? \$\endgroup\$
    – Matt Jones
    Commented Sep 29, 2013 at 16:36
  • \$\begingroup\$ No, there not, is this a problem? \$\endgroup\$ Commented Sep 29, 2013 at 16:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .