Pixel-align tile grid
Bungow

Hello,

I'm actually drawing a tilemap using ALLEGRO_TRANSFORM, the problem is when I apply scale and translation, the grid is not anymore pixel-aligned so alot of artifacts appears between tiles. I know how to solve this creating a one pixel border in the tile bitmaps, but I feel is more clean fixing this in the drawing routine, than changing all bitmaps.

So the question is: how can I floor (or similar) the final drawing position using the ALLEGRO_TRANSFORM, to ensure it's pixel are aligned?

Edgar Reynaldo

The drawing routine isn't broken. You're getting artifacts because you don't have a border around your sprites. You need that border so that the gpu knows where the end of the texture is, otherwise it will draw from the other side and wrap around, which is not what you want.

Bungow

Hello,

Thanks for you answer, but if I understand correctly, this lines appear when drawing in subpixel locations, and because of that we don't get the lines when drawing with unescaled tiles (the scale transforms make draw locations not-pixel aligned ie. 123.7346289). So the 1px border arround the texture is only a "trick" to disguise these lines, but the proper solution should be draw in pixel locations. Maybe I'm totally wrong with this. Also I'm deploying my "game" into android phone and tablet and this problems not appear, can be this because of OPENGL ES profile?

Edgar Reynaldo

Don't think of it as a 'trick'. It's just the way the hardware works. If you're upscaling your images, the sampler has to 'read' the neighbor pixels to determine the correct color. When you have RGBA 0,0,0,0 as your border color it fades to transparent and smooths the edges instead of trying to read from the other side of the image.

Bungow

Thanks

Thread #617046. Printed from Allegro.cc