Welcome!
Here is a simple solution: set "nearest" filter for your texture
https://love2d.org/wiki/FilterMode
Code: Select all
img:setFilter("nearest", "nearest")
Look at 2) option on the attached screenshot.
If it is just what you want, then no need to read further
But if you
absolutely need linear interpolation then things becames a lot more complicated, because linear interpolation needs data
outside the quad that you specified. Here is multiple ways to provide that data:
- Add one pixel rows and columns in graphic redactor outside the target quad. But it is painfull method.
- Use wrap mode provided by love textures https://love2d.org/wiki/WrapMode. But that effects happens only at the edge of texture, not at the edge of quad, so you need to crop your image in redactor or in love "phisically" (which is not preffered, but I did for clarity)
Note, if you draw cropped images with linear filtering you will still have visible line between two drawed images. Look at 3) option. To avoid that you can draw all tiled area with one quad that
extends image borders. Also it will minimize draw calls count as a bonus.
Code: Select all
function love.load()
x = 9
y = 0
w = 40
h = 33
scale = 5
love.window.setMode(w * scale * 2, (h * 4 + 3) * scale)
-- 1)
linear_img = love.graphics.newImage("myImage.png")
linear_quad = love.graphics.newQuad(x, y, w, h, linear_img:getDimensions())
-- 2)
nearest_img = love.graphics.newImage("myImage.png")
nearest_img:setFilter("nearest", "nearest")
nearest_quad = love.graphics.newQuad(x, y, w, h, nearest_img:getDimensions())
-- 3)
local croppedData = love.image.newImageData(w, h)
croppedData:paste(love.image.newImageData("myImage.png"), 0, 0, x, y, w, h)
croppedImage = love.graphics.newImage(croppedData)
-- 4)
local croppedData2 = love.image.newImageData(w, h)
croppedData2:paste(love.image.newImageData("myImage.png"), 0, 0, x, y, w, h)
croppedImage2 = love.graphics.newImage(croppedData2)
croppedImage2:setWrap("repeat")
extendedQuad = love.graphics.newQuad(0, 0, w * 2, h, croppedImage2:getDimensions())
end
function love.draw()
-- 1)
love.graphics.draw(linear_img, linear_quad, 0, 0, 0, scale, scale)
love.graphics.draw(linear_img, linear_quad, scale * w, 0, 0, scale, scale)
-- 2)
love.graphics.draw(nearest_img, nearest_quad, 0, (h + 1) * scale, 0, scale, scale)
love.graphics.draw(nearest_img, nearest_quad, scale * w, (h + 1) * scale, 0, scale, scale)
-- 3)
love.graphics.draw(croppedImage, 0, (h + 1) * scale * 2 , 0, scale, scale)
love.graphics.draw(croppedImage, scale * w, (h + 1) * scale * 2, 0, scale, scale)
-- 4)
love.graphics.draw(croppedImage2, extendedQuad, 0, (h + 1) * scale * 3, 0, scale, scale)
end