main.lua
Code: Select all
function love.load()
-- setup thread
thread = love.thread.newThread("thread.lua")
toThreadChannel = love.thread.getChannel("toThread")
fromThreadChannel = love.thread.getChannel("fromThread")
thread:start()
winW = love.graphics.getWidth()
winH = love.graphics.getHeight()
imageData = love.image.newImageData(winW, winH)
image = love.graphics.newImage( imageData )
toThreadChannel:push(imageData)
print("loaded")
end
function love.draw()
local tempImageData = fromThreadChannel:pop()
print("popped")
if tempImageData then
print("recieved Image")
imageData = tempImageData
image = love.graphics.newImage( imageData )
else
print("no image recieved")
end
love.graphics.setColor(255,255,255,128)
love.graphics.draw(image)
end
function love.keypressed(key)
if key == "q" or key == "escape" then
love.event.push('quit')
end
end
Code: Select all
print("thread started")
toThreadChannel = love.thread.getChannel("toThread")
fromThreadChannel = love.thread.getChannel("fromThread")
function drawFunction(x, y, r, g, b, a)
-- perform computations giving the new values for r, g, b and a
a = 255
r = x*y
g = x*y
b = x*y
return r, g, b, a
end
print("waiting on imageData")
imageData = toThreadChannel:demand()
print("got it: ".. type(imageData))
imageData:mapPixel( drawFunction )
print("sending image")
fromThreadDataChannel:push(imageData)
print("sent")
Code: Select all
thread started
waiting on imageData
loaded
got it: userdata
popped
no image recieved
popped
no image recieved
popped
no image recieved
popped
no image recieved
popped
no image recieved
popped
no image recieved
popped
no image recieved