LWJGL/Slick texture wrapping

Started by Bingo90, September 02, 2013, 08:03:42

Previous topic - Next topic

Bingo90

CLAMP_TO_BORDER didn't do anything.

Cornix

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.

Bingo90

CLAMP_TO_EDGE didn't do anything like CLAMP. How do I define a border color?

quew8

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.

Cornix

You specify the border color like this:
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).
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);

Bingo90

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

quew8

The texture coordinates of the sprite.

Bingo90

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?

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

quew8

Provided that
1-0.5f/(float)texture.getTextureWidth();

is the same as
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.

Bingo90

Okay the drawing method looks like this now:

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.

Bingo90

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.

Bingo90

OK, I couldn't solve it  by myself. Have you got any more advices?

quew8

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.

Bingo90

Well, I'm not sure if you answered if my try to do the half pixel correction is right.

quew8

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.