"draw_line" and Grid (SOLVED...maybe)

I’m trying to draw some grids with draw_line(for tilemap someday).
However, there is some blurred lines on right side.
Any way to resolve these annoying lines?

Thanks.

(Defold Engine 1.2.103 (d126b03))

local TILE_SIZE = 16
-- 720px
local SCREEN_WIDTH = tonumber(sys.get_config("display.width"))
-- 720px
local SCREEN_HEIGHT = tonumber(sys.get_config("display.height"))

function update(self, dt)
    drawGrid()
end

function drawGrid()
	local color = vmath.vector4(0.25, 0.25,0.25, 1)
	local line_count = SCREEN_WIDTH / TILE_SIZE
	local x = 0
	for i=1, line_count do
		msg.post("@render:", "draw_line", { start_point = vmath.vector3(0, x, 1), end_point = vmath.vector3(SCREEN_WIDTH, x, 1), color = color } )
		msg.post("@render:", "draw_line", { start_point = vmath.vector3(x, 0, 1), end_point = vmath.vector3(x, SCREEN_HEIGHT, 1), color = color } )
        x = x + TILE_SIZE -1
		msg.post("@render:", "draw_line", { start_point = vmath.vector3(0, x, 1), end_point = vmath.vector3(SCREEN_WIDTH, x, 1), color = color } )
		msg.post("@render:", "draw_line", { start_point = vmath.vector3(x, 0, 1), end_point = vmath.vector3(x, SCREEN_HEIGHT, 1), color = color } )
		x = x + 1
	end
end

Hey!

draw_line is exclusively meant to help with debugging, and of very little use for anything meant to appear in the final game. draw_line is both incredibly slow and suffers from aliasing. As strange it might sound, in your case you could be better off using a tilemap where every cell has a texture with the grey borders you are after.
I can’t really explain the blurred lines (which seems to be two lines with a 1-pixel gap), but it could be that your window (and consequently the render-target or back-buffer) does not match the width/height perfectly, which would cause the lines to end up on different pixel-lines. This could happen if the window width is actually larger than 720. You can test this by changing the size of the window and see if the blur changes.

2 Likes

I tested with several display.width/height.
896896 and 960960 does not show blurred lines, but 320320 and 912912 does. So strange…

Not sure what is difference, but at least 896896 or 960960 solved this problem :sweat_smile:

1 Like