I'm trying to do resolution independent rendering of moving sprites in a 2D game. My plan is work in a fixed coordinate system in my world (for example 960x540) and use orthographic projection to scale that up or down to fit the viewport. I do letterboxing to handle different aspect ratios.
According to most tutorials, I am free to use whatever dimensions I like for the view frustum, but I found that in many cases that leads to the problem that I end up using subpixel values on the viewport. For example a vertex at (62,62) in a coordinate system of 960 x 540 ends up at (51.6666667,51.6666667) on a viewport with the dimensions 800 x 450.
I noticed two kinds of problems with that:
- the texture sampling changes all the time for objects that are in motion depending on where the vertices are in relation to a pixels center
- my objects get stretched horizontally or vertically by a pixel from time to time due to rounding
What is the best practice to avoid this (while maintaining resolution independence in terms of movement speeds and so on)? And where would be the best place to do address this? Before passing the vertices to the shaders or inside the vertex shader?