Hello Guest

LWJGL/Slick texture wrapping

  • 30 Replies
  • 16584 Views
Re: LWJGL/Slick texture wrapping
« Reply #15 on: September 14, 2013, 16:37:58 »
CLAMP_TO_BORDER didn't do anything.

*

Offline Cornix

  • *****
  • 488
Re: LWJGL/Slick texture wrapping
« Reply #16 on: September 14, 2013, 17:01:14 »
You need to define a border color in order to make CLAMP_TO_BORDER work.
Without a border color you need to use CLAMP_TO_EDGE.

Re: LWJGL/Slick texture wrapping
« Reply #17 on: September 15, 2013, 06:28:52 »
CLAMP_TO_EDGE didn't do anything like CLAMP. How do I define a border color?

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: LWJGL/Slick texture wrapping
« Reply #18 on: September 15, 2013, 10:16:32 »
What about my half-pixel correction? You need to change the way you assign texture coordinates to your sprite as I showed in the previous post.

*

Offline Cornix

  • *****
  • 488
Re: LWJGL/Slick texture wrapping
« Reply #19 on: September 15, 2013, 11:00:06 »
You specify the border color like this:
Code: [Select]
GL11.glTexParameter(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_BORDER_COLOR, someFloatBuffer);But you have to also increase the width and height of your texture by 2 (the border is 1 pixel in size).
Code: [Select]
int borderSize = 1;
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width + 2, height + 2, borderSize, GL11.GL_RGBA, GL11.GL_FLOAT, someFloatBuffer);

Re: LWJGL/Slick texture wrapping
« Reply #20 on: September 15, 2013, 11:28:47 »
I'll try the pixel correction thing. I don't use LWJGL directly to load a texture.

EDIT:

What should I change? I not sure what in my code should be 0.5 higher/lower
« Last Edit: September 15, 2013, 11:31:58 by Bingo90 »

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: LWJGL/Slick texture wrapping
« Reply #21 on: September 16, 2013, 16:22:07 »
The texture coordinates of the sprite.

Re: LWJGL/Slick texture wrapping
« Reply #22 on: September 17, 2013, 12:49:32 »
OK I'll try that

Edit:

I tried it but it didn't work. I used 0.5f/(float)texture.getTextureWidth() and 0.5f/(float)texture.getTextureHeight(), is this right?

Code: [Select]
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0.5f/(float)texture.getTextureWidth(), 0.5f/(float)texture.getTextureHeight());
GL11.glVertex2f(0,0);
GL11.glTexCoord2f(1-0.5f/(float)texture.getTextureWidth(),0.5f/(float)texture.getTextureHeight());
GL11.glVertex2f(texture.getTextureWidth(),0);
GL11.glTexCoord2f(1-0.5f/(float)texture.getTextureWidth(),1-0.5f/(float)texture.getTextureHeight());
GL11.glVertex2f(texture.getTextureWidth(),texture.getTextureHeight());
GL11.glTexCoord2f(0.5f/(float)texture.getTextureWidth(),1-0.5f/(float)texture.getTextureHeight());
GL11.glVertex2f(0,texture.getTextureHeight());

GL11.glEnd();
« Last Edit: September 18, 2013, 12:48:24 by Bingo90 »

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: LWJGL/Slick texture wrapping
« Reply #23 on: September 17, 2013, 18:53:00 »
Provided that
Code: [Select]
1-0.5f/(float)texture.getTextureWidth();
is the same as
Code: [Select]
1 - ( 0.5f/(float)texture.getTextureWidth() );
I always use brackets everywhere to avoid any ambiguity whatsoever the result of which is I don't actually know the operator precedence in Java.

Also something that I think I forget to mention before, GL_TEXTURE_MAG_FILTER and GL_TEXTURE_MIN_FILTER should really be set to GL_NEAREST really.

If the above is the case and it still isn't working, then if you say what is happening (as opposed to just "it didn't work") then we will be in a position to help.

Re: LWJGL/Slick texture wrapping
« Reply #24 on: September 18, 2013, 12:52:59 »
Okay the drawing method looks like this now:

Code: [Select]
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);


GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0.5f/(float)texture.getTextureWidth(), 0.5f/(float)texture.getTextureHeight());
GL11.glVertex2f(0,0);
GL11.glTexCoord2f(1-0.5f/(float)texture.getTextureWidth(),0.5f/(float)texture.getTextureHeight());
GL11.glVertex2f(texture.getTextureWidth(),0);
GL11.glTexCoord2f(1-0.5f/(float)texture.getTextureWidth(),1-0.5f/(float)texture.getTextureHeight());
GL11.glVertex2f(texture.getTextureWidth(),texture.getTextureHeight());
GL11.glTexCoord2f(0.5f/(float)texture.getTextureWidth(),1-0.5f/(float)texture.getTextureHeight());
GL11.glVertex2f(0,texture.getTextureHeight());

GL11.glEnd();

GL11.glLoadIdentity();
}

But the "pixel lines" are still the same as on the first post.
« Last Edit: September 18, 2013, 14:39:59 by Bingo90 »

Re: LWJGL/Slick texture wrapping
« Reply #25 on: September 19, 2013, 12:57:26 »
Seems to be difficult to fix :(
EDIT: By the way I don't think I've mentioned, that the textures are seperate files not one image.
« Last Edit: September 21, 2013, 13:59:59 by Bingo90 »

Re: LWJGL/Slick texture wrapping
« Reply #26 on: September 22, 2013, 13:13:35 »
OK, I couldn't solve it  by myself. Have you got any more advices?

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: LWJGL/Slick texture wrapping
« Reply #27 on: September 22, 2013, 19:01:37 »
As I said before, its called texture bleeding. I've given you two solutions already so I think the best thing now would be to look through the various solutions for yourself. If you have issues with or want clarification on a method then we can help but this really is a matter of personal preference.

Re: LWJGL/Slick texture wrapping
« Reply #28 on: September 23, 2013, 16:38:34 »
Well, I'm not sure if you answered if my try to do the half pixel correction is right.
« Last Edit: September 25, 2013, 16:31:12 by Bingo90 »

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: LWJGL/Slick texture wrapping
« Reply #29 on: September 26, 2013, 21:29:21 »
It looks right to me. But as I've said I've never done any of this. I just add a border around my textures where its needed. That is built into my texture loading code so once its loaded I just forget about it. If nothing else works then it really isn't that bad a solution.