sdl-gpu
sdl-gpu copied to clipboard
Snapping is performed before scaling which produces flickering
In tests/pixel-perfect/main.c I added camera.zoom = 0.5 and switched filtering to NEAREST by pressing 'f' (but the effect is observed without this as well).
When I move rectangles by 1.0 they flicker, i.e.: when y=0: 0-st, 2-nd, 4-th lines of the image are drawn when y=1: 1-st, 3-rd, 5-th lines are drawn when y=2: 0-st, 2-nd, 4-th lines are drawn and the image is moved down 1 pixel row
Am I right that snapping is applied before scaling? I think it would be better for pixel art games to apply snapping to the resulting vertices, i.e.: when y=0: 0-st, 2-nd, 4-th lines are drawn when y=1: 0-st, 2-nd, 4-th lines are drawn when y=2: 0-st, 2-nd, 4-th lines are drawn and image is moved down 1 pixel row etc
upd:
float k = 1.0 / camera.zoom;
float y_ = floorf((y + image->h/2) / k) * k;
float x_ = floorf((x + image->w/2) / k) * k;
GPU_Blit(image, NULL, screen, x_, y_);
//GPU_Blit(image, NULL, screen, floorf(x + image->w/2), floorf(y + image->h/2));
I've tried disabling snap and rounding the values manually and this fixed the flickering. Should this be a separate snapping mode? For example, Oxygine has OXYGINE_NO_SUBPIXEL_RENDERING, Cocos also has a similar mode. http://oxygine.org/doc/api/_renderer_8h_source.html
I'm not confident that the snapping code is really that good (I haven't given it any attention in a long time). If you do improve it, I'd appreciate a pull request. If not, I'll see how I can work this in when I have the chance.
I am having problems with pixel perfect scaling of textures and ended up here while searching for clues. Any news about this?
Thanks