Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (578)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LWJGL Nearest Neighbor filter has artifacts without scaling?  (Read 1285 times)
0 Members and 1 Guest are viewing this topic.
Offline DrewLols

Senior Duke


Medals: 3
Projects: 1


Noob going through metamorphosis...


« Posted 2013-04-19 00:13:05 »

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...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
   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
1  
2  
      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?

Did you know that 90% of statistics are wrong?
Offline theagentd
« Reply #1 - Posted 2013-04-19 00:30:41 »

Pics or it didn't happen.  Wink

Myomyomyo.
Offline DrewLols

Senior Duke


Medals: 3
Projects: 1


Noob going through metamorphosis...


« Reply #2 - Posted 2013-04-19 04:28:03 »

It's kinda hard to tell when the image is not moving.



Well, it's easier to tell with the text.  The textures are just so jagged, and I KNOW I haven't done any scaling...  The font class is my own as well, just fyi.  I am using SlickUtil to load textures.  Is there a particular way I need to be loading textures?  Perhaps I specify a filter upon creating the texture?

Did you know that 90% of statistics are wrong?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DrewLols

Senior Duke


Medals: 3
Projects: 1


Noob going through metamorphosis...


« Reply #3 - Posted 2013-04-19 04:42:00 »

I am the dumb stupid...  I set Display's window size to 600x400, but I left glOrtho as...
1  
GL11.glOrtho(0, 640, 480, 0, 1, -1);


Ouch...  That's what I get for copying code snippets, I guess...

Did you know that 90% of statistics are wrong?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

DarkCart (6 views)
2014-10-31 21:44:48

DarkCart (7 views)
2014-10-31 21:43:57

TehJavaDev (38 views)
2014-10-27 03:28:38

TehJavaDev (29 views)
2014-10-27 03:27:51

DarkCart (43 views)
2014-10-26 19:37:11

Luminem (24 views)
2014-10-26 10:17:50

Luminem (29 views)
2014-10-26 10:14:04

theagentd (35 views)
2014-10-25 15:46:29

Longarmx (63 views)
2014-10-17 03:59:02

Norakomi (61 views)
2014-10-16 15:22:06
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!