Hello Guest

Lines appearing next to a texture

  • 4 Replies
  • 89 Views
Lines appearing next to a texture
« on: August 04, 2018, 20:53:37 »
So I tried to basically render an image/texture in 2D mode just like in the LWJGL tutorials, but some lines show up right next and under the image. I´ve tried using a different png image without transparency and it doesn´t happen.
I tried another png image with transparency and the lines show up again.
I saw a guy mentioning i need to use:

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);      
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

after

glEnable(GL_TEXTURE_2D);

but its not recognizing GL_CLAMP_TO_EDGE so I can´t try that.
Any help?

*

Offline KaiHH

  • ***
  • 118
Re: Lines appearing next to a texture
« Reply #1 on: August 05, 2018, 07:20:50 »
but its not recognizing GL_CLAMP_TO_EDGE so I can´t try that.
This static field is declared in org.lwjgl.opengl.GL13, so you can use it like so:
Code: [Select]
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, org.lwjgl.opengl.GL13.GL_CLAMP_TO_EDGE);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, org.lwjgl.opengl.GL13.GL_CLAMP_TO_EDGE);
Or add a static import to that field, just like you apparently did it for GL_TEXTURE_2D and the other static fields from GL11, too.

Re: Lines appearing next to a texture
« Reply #2 on: August 05, 2018, 18:23:55 »
You were right! I had only imported GL11, tho, GL_CLAMP_TO_EDGE is from GL12, not GL13.
But still, the problem persists, I´ve tried just clamp, clamp to border, to edge and nothing.
Although, after trying with an image from the internet, it didn´t show up those lines, whereas with my handmade images it does.
Is there a magic trick in the way you export the file to a PNG so the lines don´t show up that I´m unaware?

*

Offline Cornix

  • *****
  • 479
Re: Lines appearing next to a texture
« Reply #3 on: August 05, 2018, 19:52:47 »
It has probably nothing to do with the image itself (unless you actually have those lines IN your image but I guess you dont) but with the way the texels are rasterized. Clamping only works if the area of the texture that you are drawing is equal to the entire size of the texture. If you are using a texture atlas and only drawing a portion of it clamping will not help. In this case you need to either change the filters to a nearest neighbour filter or add a transparent border around each part of the texture atlas.

Re: Lines appearing next to a texture
« Reply #4 on: August 05, 2018, 21:51:49 »
It has probably nothing to do with the image itself (unless you actually have those lines IN your image but I guess you dont) but with the way the texels are rasterized. Clamping only works if the area of the texture that you are drawing is equal to the entire size of the texture. If you are using a texture atlas and only drawing a portion of it clamping will not help. In this case you need to either change the filters to a nearest neighbour filter or add a transparent border around each part of the texture atlas.
Ok, let me see I actually understood that as a newbie that I am.
The problem is not from the image but from how openGL is interpreting the image and translating its data into actual pixel to the screen.By using a texture atlas I don´t really know what you mean, but I´d say I´m not. I have 2 methods defined for drawing images, one that allows me to define the actual size I want to draw the image at, and the other one uses the actual image size, but both seem to make the lines appear (btw, I´m trying to keep this royect with a high level of abstraction, so I´m using slick´s resource loader to load the image and whatnot).
So please, could you detail a bit more the infor you just gave me, because didn´t really caught the second part.
Also, I don´t know if this:

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

is setting the filter to nearest neighbor as you sugested, but it still doesn´t work :(