So, I’m trying to build my own gaming library, and I am writing my own TiledMap class. Problem is, whenever I load in any sprite and apply a nearest neighbor filter like…
public void render()
{
texture.bind();
// Filter code
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
// Mins and maxes for which parts of the image to select
float minX = srcX / (float)texture.getTextureWidth();
float minY = srcY / (float)texture.getTextureHeight();
float maxX = srcX2 / (float)texture.getTextureWidth();
float maxY = srcY2 / (float)texture.getTextureHeight();
// Begins drawing a quad
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(minX, minY);
GL11.glVertex2f(0, 0);
GL11.glTexCoord2f(maxX, minY);
GL11.glVertex2f(srcX2 - srcX, 0);
GL11.glTexCoord2f(maxX, maxY); //
GL11.glVertex2f(srcX2 - srcX, srcY2 - srcY);
GL11.glTexCoord2f(minX, maxY); //
GL11.glVertex2f(0, srcY2 - srcY);
GL11.glEnd();
}
the edges of the texture look kinda wavy, almost like some pixels are slightly ahead of each other sometimes. I have not scaled anything, and the camera’s coordinates are changing, but rounded. I really don’t know why there would be visual artifacts like this.
The code
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
should have handled the nearest neighbor filtering for me, and it DOES prevent LWJGL from rendering a particular texture in a smooth manner when scaling, but it shouldn’t be jagged when the coordinates are rounded! Any clues?