To be brief, I'm trying to render an image distorted by a sinusoid but I realize that it's really slow (obviously since it's displayed pixel by pixel). So I looked for a way to render it "directly in a texture" and display it (much like in "pure SDL") but I couldn't find an equivalent in love. I tried other techniques with canvas but they were totally flawed...
Here is a mini code that I wrote as a demo, if someone can direct me to a more suitable solution.
I'm running around 30 FPS at home with this example.
Code: Select all
local WIN_W, WIN_H
local image = {}
local phase
function love.load()
local imageData = love.image.newImageData("image.png")
WIN_W, WIN_H = love.graphics.getDimensions()
image.w, image.h = imageData:getDimensions()
image.x = (WIN_W-image.w) / 2
image.y = (WIN_H-image.h) / 2
image.pixels = {}
for x = 0, image.w - 1 do
for y = 0, image.h - 1 do
local r, g, b, a = imageData:getPixel(x, y)
image.pixels[y * image.w + x] = {r, g, b, a}
end
end
phase = 0
end
function love.update(dt)
phase = phase + 5 * dt
end
function love.draw()
love.graphics.print("FPS: "..tostring(love.timer.getFPS( )), 0, 0)
-- Draw distorted image --
for x = 0, image.w - 1 do
for y = 0, image.h - 1 do
local x_sin = 10 * math.sin(y * .05 + phase)
love.graphics.setColor(
image.pixels[y * image.w + x]
)
love.graphics.points(
image.x + x + x_sin,
image.y + y
)
end
end
love.graphics.setColor(1,1,1)
end