Orthographic unit translation mismatch on grid (e.g. 64 pixels translates incorrectly)
- by Justin Van Horne
I am looking for some insight into a small problem with unit translations on a grid.
Setup
512x448 window
64x64 grid
gl_Position = projection * world * position;
projection is defined by ortho(-w/2.0f, w/2.0f, -h/2.0f, h/2.0f); This is a textbook orthogonal projection function.
world is defined by a fixed camera position at (0, 0)
position is defined by the sprite's position.
Problem
In the screenshot below (1:1 scaling) the grid spacing is 64x64 and I am drawing the unit at (64, 64), however the unit draws roughly ~10px in the wrong position. I've tried uniform window dimensions to prevent any distortion on the pixel size, but now I am a bit lost in the proper way in providing a 1:1 pixel-to-world-unit projection. Anyhow, here are some quick images to aide in the problem.
I decided to super-impose a bunch of the sprites at what the engine believes is 64x offsets.
When this seemed off place, I went about and did the base case of 1 unit. Which seemed to line up as expected. The yellow shows a 1px difference in the movement.
Vertices
It would appear that the vertices going into the vertex shader are correct. For example, in reference to the first image the data looks like this in the VBO:
x y x y
----------------------------
tl | 0.0 24.0 64.0 24.0
bl | 0.0 0.0 -> 64.0 0.0
tr | 16.0 0.0 80.0 0.0
br | 16.0 24.0 80.0 24.0
With that said, all I am left to believe is that I am munging up my actual projection. So, I am looking for any insight into maintaining the 1:1 pixel-to-world-unit projection.