Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Pixel / Scaling Error  (Read 970 times)
0 Members and 1 Guest are viewing this topic.
Offline sjk

Senior Newbie





« Posted 2013-07-04 13:44:49 »

I noticed a couple of strange pixel Errors in my Game and got no idea where they would come from. There's an image attached which shows three of them. They could be related too each other but I'm not sure. I also included some of my code. Any help would be appreciated! Smiley
If there's anything I should explain in more detail let me know. Thanks!


1. The first one is a problem with my text rendering. On the top right is the original text and beneath it is a magnification. As you can see it looks really messed up. There are some pixels missing etc. Beneath that you can see the original texture. The texture sheet itself is really small. But increasing the size didn't help.

2. The second one are the turquoise boxes which represent my collision objects. They render fine but when I move the camera there is a chance that some of the lines disappear. Also marked with red Arrows. I'm using GL_LINE_LOOP for those.

3. The third one isn't that big but still strange. On the ground floor of the building below the ceiling there is a small offset in the texture. Only by one pixel or so. If the camera is moved the error appears / disappears. On the bottom is a side by side comparison of the ingame texture and the orignal one.



Edit: The picture seems to be to wide, you can scroll to the right to see the rest of it..

Text drawing:
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  
27  
      fontColor.bind();
      glEnable(GL_TEXTURE_2D);
      TextureHelper.hashtable.get("font1.png").bind();
     
      for(int i = 0; i < inputString.length(); i ++) {
         int asciiCode = (int)inputString.charAt(i);
         
         //ascii position minus first character in texture sheet (in this case " " / Space)
        asciiCode -= 32;
         //get tileX for char by ascii position modulo table width
        int tileX = asciiCode % 16;
         //get tileY for char by ascii position divided by table width
        int tileY = asciiCode / 16;
         
         float offset = size * i;
         
         glBegin(GL_QUADS);
            glTexCoord2f(0.0625f * tileX, 0.125f * tileY);
            glVertex3f(posX + offset, posY, depth);
            glTexCoord2f(0.0625f * (tileX + 1), 0.125f * tileY);
            glVertex3f(posX + size + offset, posY, depth);
            glTexCoord2f(0.0625f * (tileX + 1), 0.125f * (tileY + 1));
            glVertex3f(posX + size + offset, posY + size, depth);
            glTexCoord2f(0.0625f * tileX, 0.125f * (tileY + 1));
            glVertex3f(posX + offset, posY + size, depth);
         glEnd();
      }


Texture drawing and lineloop drawing:
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  
27  
28  
29  
30  
31  
32  
33  
   public static void texQuad(Texture texture, float xPosition, float yPosition, float xSize, float ySize, float depth) {
      glEnable(GL_TEXTURE_2D);
      Color.white.bind();
      try {
         texture.bind();
      } catch (NullPointerException e) {
         e.printStackTrace();
         glDisable(GL_TEXTURE_2D);
         glColor4f(198.0f / 255.0f, 0.0f / 255.0f, 255.0f / 255.0f, 1.0f);
      }
      glBegin(GL_QUADS);
         glTexCoord2f(0,0);
         glVertex3f(xPosition, yPosition, depth);
         glTexCoord2f(1,0);
         glVertex3f(xPosition + xSize, yPosition, depth);
         glTexCoord2f(1,1);
         glVertex3f(xPosition + xSize, yPosition + ySize, depth);
         glTexCoord2f(0,1);
         glVertex3f(xPosition, yPosition + ySize, depth);
      glEnd();
   }
   
   public static void lineLoop(Color color, float xPosition, float yPosition, float xSize, float ySize, float depth) {
      glDisable(GL_TEXTURE_2D);
      color.bind();
      glBegin(GL_LINE_LOOP);
         glTexCoord2f(0,0);
         glVertex3f(xPosition,          yPosition,          depth);
         glVertex3f(xPosition + xSize,    yPosition,          depth);
         glVertex3f(xPosition + xSize,    yPosition + ySize,    depth);
         glVertex3f(xPosition,          yPosition + ySize,    depth);
      glEnd();
   }


Camera:
1  
2  
3  
4  
5  
      glOrtho(Player.xPosition - Game.resolution.width  / 2 * InGame.camScale, 
            Player.xPosition + Game.resolution.width  / 2 * InGame.camScale,
            Player.yPosition + Game.resolution.height / 2 * InGame.camScale,
            Player.yPosition - Game.resolution.height / 2 * InGame.camScale,
            20, -20);
Offline davedes
« Reply #1 - Posted 2013-07-04 17:39:16 »

1. Scaling your bitmap fonts will always lead to aliasing. If you want to get rid of aliasing for small fonts, the best solution is to use a series of bitmap fonts of different sizes. This can be expensive and annoying if you need a lot of sizes, unless you are smart about packing glyphs into the same atlas. LibGDX includes a lot of utilities for this sort of thing.

2. Probably due to pixel offsets or something with OpenGL rasterizer. You don't have much control over that, since you are using GL_LINE_LOOP, which is not always reliable. I would recommend using two triangles to render a line, as strange as that may seem. You can include them in a sprite batch for faster rendering:
https://github.com/mattdesl/lwjgl-basics/wiki/Batching-Rectangles-and-Lines

You may still run into rendering blurriness and aliasing issues if you are rendering the lines at non-integer coordinates.

3. Again, most likely due to rendering and scaling your sprites at non-integer coordinates. Small floating point errors will lead to some unwanted effects.

My suggestion would be to not scale your textures if you need to get rid of these aliasing problems.

Offline sjk

Senior Newbie





« Reply #2 - Posted 2013-07-05 12:14:34 »

Awesome thanks! That makes sense I guess. My font is only 8 pixels high and it looks I'm save as long as I only use text sizes double that size etc.

I'll definitely check out your line rendering method, but for know I'll just keep using GL_LINE_LOOP since it's only for debugging and not that important.

Also I was able to clean up my interface by just rendering the textures in the right size. Seems pretty logical in retrospect...

Thanks again!
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.

BurntPizza (17 views)
2014-09-19 03:14:18

Dwinin (34 views)
2014-09-12 09:08:26

Norakomi (61 views)
2014-09-10 13:57:51

TehJavaDev (84 views)
2014-09-10 06:39:09

Tekkerue (42 views)
2014-09-09 02:24:56

mitcheeb (64 views)
2014-09-08 06:06:29

BurntPizza (47 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (39 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!