Pages: 1
  Print  
Author Topic: Half Pixel Alignment  (Read 745 times)
Offline (Male) Goombert
Posted on: July 27, 2013, 06:16:10 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3110

View Profile
If any of you have ever worked with SVG or other vector graphics then you know you need to do half pixel alignment. OpenGL and DirectX work the same way. If nobody noticed, there was a bug where drawing an outlined rectangle wouldn't fill the pixel in each of its 4 corners, that was due to half pixel alignment.

I resolved this by changing the orthographic projection code to offset by half pixels instead of full pixels.
Code: [Select]
glOrtho(x-1,x + width,y-1,y + height,0,1);
Should have been...
Code: [Select]
glOrtho(x-0.5,x + width,y-0.5,y + height,0,1);

Anyway I am committing the fix soon and 2D stuff will no longer be misaligned or have edge artifacts. This was just a friendly reminder to everyone. Also be aware that DirectX9 eclusively has a half texel bug regarding sampling which must be resolved in a shader.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) TheExDeus
Reply #1 Posted on: July 28, 2013, 05:26:04 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
This was also fixed by changing the drawing functions to have a half-pixel offset a few days ago.
Logged
Pages: 1
  Print